Problem Attacching Images to Mails

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!

You mention Standalone, but at the point where you use WWW to load image (why?), it looks more like an Android Uri to access something from within Jar (how does that even work in editor??)

I think it work because that part isn’t working while in editor mode { if (Application.platform == RuntimePlatform.WindowsEditor)}.
I don’t know why the WWW stands for, I used a code I found that seems to work (but doesn’t).

Please use the “Insert code” feature when pasting code in forum, that results in a way more readable thing.
And it looks to be an issue in the else part there. The code tries to load something from jar, which is android-only, so in Windows Standalone that will fail, error is ignored so a 0 byte file is written.

Got to say it, dear god please ensure this code is used for ‘internal use only’ and doesn’t ship in your game or app.

Thanks for the help, I’ll check it out