Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

send email with attachment

Discussion in 'iOS and tvOS' started by ovion, May 3, 2014.

  1. ovion

    ovion

    Joined:
    Jul 12, 2012
    Posts:
    7
    Hello guys,
    I want to send an email with attachment from an ipad and i followed this steps:
    I use Application.CaptureScreenshot("screenshot.png") in Start().
    For email i use this Coroutine:
    Code (csharp):
    1.  
    2. private IEnumerator sendAutoMail (string textBody,string title)
    3.     {
    4.         MailMessage mail = new MailMessage();
    5.        
    6.         mail.From = new MailAddress("News");
    7.         mail.To.Add("user1@gmail.com");
    8.         mail.Subject = title;
    9.         mail.Body = textBody;
    10.         string filename = "screenshot.png";
    11.         mail.Attachments.Add (new Attachment(Application.persistentDataPath+ "/"+ filename));
    12.         SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
    13.         smtpServer.Port = 587;
    14.         smtpServer.Credentials = new System.Net.NetworkCredential("user@gmail.com", "password") as ICredentialsByHost;
    15.         smtpServer.EnableSsl = true;
    16.         ServicePointManager.ServerCertificateValidationCallback =
    17.             delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
    18.         { return true; };
    19.         smtpServer.Send(mail);
    20.         yield return null;
    21.     }
    22.  
    It is working in Editor but it si NOT working on iPad. I searched the forum and tried all the solutions, but i had no luck.
    If i remove the line
    Code (csharp):
    1. mail.Attachments.Add (new Attachment(Application.persistentDataPath+ "/"+ filename));
    it is working perfect (without attachment).
    The problem seems to be with the path to the image, but i do not know how to solve it. I tried with Application.temporaryCachePath instead of Application.persistentDataPath, but is not working.
    Can you help me with?
     
  2. u3dxt

    u3dxt

    Joined:
    Jul 6, 2013
    Posts:
    317
  3. Mayank516

    Mayank516

    Joined:
    Nov 17, 2014
    Posts:
    7
  4. kaarloew

    kaarloew

    Joined:
    Nov 1, 2018
    Posts:
    360
    Are you astroturfing your own plugins? And same time necroing a thread that is over 7 years old?