简体   繁体   English

无法在Unity3D中的手机中发送电子邮件?

[英]Unable To Sent Email In Mobiles in Unity3D?

I Need to Send Mail by Using mobile,the below code sends mail in systems but not send mail in mobiles.i dont understand the problem, plz help me how to send mail in mobiles.i'm using this in Andriod mobiles. 我需要使用手机发送邮件,以下代码在系统中发送邮件,但不能在手机中发送邮件。我不了解问题,请帮助我如何在手机中发送邮件。我在Andriod手机中使用此功能。

My code is: 我的代码是:

using System;
using System.IO;
using System.Collections.Generic;
using System.Net;
using System.Linq;
using System.Text;
using System.Net.Mail;
using UnityEngine;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;


public class EmailHandler : ScriptableObject
 {

     public static void SendEmail()
     {
       try
         {

        string smtp_Name;
        int port_no;
        string toAddr = "ToMailAddress@gmail.com";
        MailMessage mail = new MailMessage();
        //From address to send email
         mail.From = new MailAddress("From@gmail.com");
        //To address to send email
        mail.To.Add(toAddr);
        mail.Subject = "TEST for UNITY3D...!!!!!!";
        mail.Body = "This is a test mail from C# program";


            smtp_Name = "smtp.gmail.com";
            port_no = 587;


        SmtpClient smtpC = new SmtpClient(smtp_Name);
        smtpC.Port = port_no;

        //Credentials for From address
        smtpC.Credentials =(System.Net.ICredentialsByHost) new System.Net.NetworkCredential("Email", "Password") as ICredentialsByHost;
        smtpC.EnableSsl = true;
     ServicePointManager.ServerCertificateValidationCallback = 
            delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 
                { return true; };
        smtpC.Send(mail);

        //Change Console.Writeline to Debug.Log 
        Debug.Log ("Message sent successfully");
    }
    catch (Exception e)
    {
        Debug.Log(e.GetBaseException());
        //You don't need or use Console.ReadLine();
    }
  }  
 }

in line 排队

attachment = new System.Net.Mail.Attachment("attachment"); 附件=新的System.Net.Mail.Attachment(“附件”);

whats "attachment"??? 什么是“附件” ???

you have to specify a file name like this... 您必须指定这样的文件名...

attachment = new System.Net.Mail.Attachment("mifile.pdf"); 附件=新的System.Net.Mail.Attachment(“ mifile.pdf”);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM