Hi All,
I’ve benn looking around for a couple days and still no solution.
I try to take a screenshoot and send it via mail. In the editor everything work smoothly, but when it come to the standalone build it doesn’t work properly: the email is sent, but the image attacched is broken.
Is anyone aware of a fix?
I’ve already change the settings from .net 2.0 subs to .net 2.0.
Here is my code:
public Text DebugText;
public GameObject saveSendPanel;
public GameObject confermationPanel;
public InputField inputMail;
bool sendingEmailDone = false;
public void SendMail()
{
string FilePath = “Images/tmp.png”;
string AttachmentName = “tmp.png”;
string FileName = “tmp.png”;
string destinatario = inputMail.text;
Debug.Log("Email inserita: " + inputMail.text);
if (Application.platform == RuntimePlatform.WindowsEditor) {
FilePath = string.Format(@“Images/tmp.png”, AttachmentName);
} else {
FilePath = Application.persistentDataPath + “/” + AttachmentName;
if(!System.IO.File.Exists(FilePath)) {
WWW loadImage = new WWW(“jar:file://” + Application.dataPath + “!/Images/” + AttachmentName);
while(!loadImage.isDone) {}
System.IO.File.WriteAllBytes(FilePath, loadImage.bytes);
}
}
FileName = FilePath;
MailMessage mail = new MailMessage();
mail.From = new MailAddress(“esempio@gmail.com”);
mail.To.Add(destinatario);
mail.Subject = “eMail Subject”;
mail.Body = " Body ";
Attachment data = new Attachment(FileName, System.Net.Mime.MediaTypeNames.Application.Octet);
// Add time stamp information for the file.
System.Net.Mime.ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(FileName);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(FileName);
disposition.ReadDate = System.IO.File.GetLastAccessTime(FileName);
mail.Attachments.Add(data);
SmtpClient smtpServer = new SmtpClient(“smtp.gmail.com”);
smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential(“esempio@gmail.com”, “esempio”) as ICredentialsByHost;
smtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback =
delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) {
return true;
};
try
{
smtpServer.Send(mail);
sendingEmailDone = true;
}
catch (Exception e)
{
Debug.Log(e.GetBaseException());
sendingEmailDone = false;
DebugText.text = "Errore invio mail: " + e.GetBaseException();
DebugText.gameObject.SetActive(true);
saveSendPanel.SetActive(false);
confermationPanel.SetActive(false);
}
if (sendingEmailDone == true)
{
saveSendPanel.SetActive(false);
confermationPanel.SetActive(true);
}
}
Thank you for the help!