0

我需要使用手机发送邮件,下面的代码在系统中发送邮件但不在手机中发送邮件。我不明白这个问题,请帮助我如何在手机中发送邮件。我在 Andriod 手机中使用它。

我的代码是:

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();
    }
  }  
 }
4

1 回答 1

0

排队

附件 = 新 System.Net.Mail.Attachment("附件");

什么是“附件”???

你必须指定一个像这样的文件名......

附件 = 新 System.Net.Mail.Attachment("mifile.pdf");

于 2013-08-14T12:59:13.383 回答