2017-05-01 27 views
0

我想讓我的應用程序從應用程序內部發送電子郵件。目前使用下面的代碼發送電子郵件,但它會在發送之前先打開我的電子郵件應用如何在Unity中發送來自應用程序內部的電子郵件?

公共無效EmailUs(){

//email Id to send the mail to 
    string email = "[email protected]"; 
    //subject of the mail 
    string subject = MyEscapeURL("INQUIRY"); 
    //body of the mail which consists of Device Model and its Operating System 
    string body = ""; 
    int k = 1; 
    do { 
     body = MyEscapeURL ("Please Enter your message here\n\n\n\n" + 
     "________" + 

     Application.OpenURL ("mailto:" + email + "?subject=" + subject + "&body=" + body); 
    } while(k != num); 

} 

string MyEscapeURL (string url) 
{ 
    return WWW.EscapeURL(url).Replace("+","%20"); 
} 

是它可以從應用程序中發送電子郵件,而無需打開郵件?謝謝!

+0

歡迎來到Stack Overflow!如果你還沒有參加[旅遊],請看[問]。第一點是「搜索和研究」,你沒有展示太多的研究成果。如果您使用'Application.OpenURL'並以「mailto:」開頭,則您將始終自動打開電子郵件應用程序。你有沒有嘗試過這樣做? – PJvG

回答

1

是的,你可以,這裏是一個腳本,應該做的工作!

private MailMessage mail = new MailMessage(); 

void SendEmails() 
{ 
    mail.From = new MailAddress("GIVE_YOUR_EMAIL_HERE"); 
    mail.To.Add("GIVE_YOUR_DESTINATION_HERE"); 

    SmtpClient smtpServer = new SmtpClient("GIVE_SMTP_INFO_HERE"); 
    smtpServer.Port = 587;//GIVE CORRECT PORT HERE 
    mail.Subject = "WHATEVER_YOU_WANT_TEXT"; 
    mail.Body = "WHATEVER_YOU_WANT_TEXT"; 
    smtpServer.Credentials = new System.Net.NetworkCredential("GIVE_SMTP_INFO_HERE", "GIVE_YOUR_EMAIL_PASSWORD_HERE") as ICredentialsByHost; 
    smtpServer.EnableSsl = true; 
    ServicePointManager.ServerCertificateValidationCallback = 
    delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 
    { return true; }; 
    smtpServer.Send(mail); 
    //smtpServer.SendAsync(mail) 
    Debug.Log("success"); 
} 
+0

無需其他配置? – Janella

+0

我不記得了,一年前我做過了,但我不相信。 – Hristo

+1

@Janella當然,您需要提供一些SMPT細節('GIVE_SMTP_INFO_HERE'幾乎不是服務器名稱)。如果您沒有服務器,或者您擁有的服務器不接受電子郵件並實際發送郵件,請查看Mail Chimp服務 – Draco18s

相關問題