In code to send an email from a game built using Unity I have the line:
SmtpServer.Credentials = (ICredentialsByHost)new System.Net.NetworkCredential(username, password);
Where SmtpServer is an instance of System.Net.SmtpClient (Just to be confusing!).
On all platforms I’ve tried this on it works fine, including the Unity Editor on Windows 8.1, except when run as a standalone build on Windows 8.1 where I get an InvalidCastException…
I can’t see a reason for the exception, particulally considering that NetworkCredentials implements the ICredentialsByHost interface so I’m left thinking Unity’s export is doing something?
Larger snippet of code:
//Create an SMTP server conection
SmtpServer = new SmtpClient(SMTPAddress);
SmtpServer.Port = SMTPPort;
SmtpServer.Credentials = (ICredentialsByHost)new System.Net.NetworkCredential(username, password);
SmtpServer.EnableSsl = useSSL;
SmtpServer.Timeout = timeout;
Thanks ![]()