0
//aspx.cs file    
protected void SendButton_Click(object sender, EventArgs e)
{
    MailHelper.SendMailMessage("naresh7590@gmail.com", "cheekucheekuarena@gmail.com", "", "", "Sample Subject", "Sample body of text for mail message");
}


//MailHelper.cs
 using System.Net.Mail;

public class MailHelper
{
    public static void SendMailMessage(string from, string to, string bcc, string cc, string subject, string body)
    {
        MailMessage mMailMessage = new MailMessage();
        mMailMessage.From = new MailAddress(from);
        mMailMessage.To.Add(new MailAddress(to));


        if ((bcc != null) && (bcc != string.Empty))
        {
            mMailMessage.Bcc.Add(new MailAddress(bcc));
        }

        if ((cc != null) && (cc != string.Empty))
        {
            mMailMessage.CC.Add(new MailAddress(cc));
        }      

        mMailMessage.Subject = subject;
        mMailMessage.Body = body;

        mMailMessage.IsBodyHtml = true;
        mMailMessage.Priority = MailPriority.Normal;

        SmtpClient mSmtpClient = new SmtpClient("127.0.0.1");
        mSmtpClient.Send(mMailMessage);//Error here
    }
}

我在mSmtpClient.Send(mMailMessage).

你能帮我吗?

4

2 回答 2

0

鉴于发件人地址是 gmail 帐户,我假设您正在尝试通过 GMAIL 发送电子邮件,如果不是,则本地计算机中的 SMTP 服务器存在问题。我希望这有帮助:

    public static void SendMailMessage(string from, string to, string bcc, string cc, string subject, string body)
    {
        //Creating Mail Message
        var mMailMessage = new MailMessage(from, to, subject, body);
        if (!String.IsNullOrEmpty(bcc))
            mMailMessage.Bcc.Add(bcc);
        if (!String.IsNullOrEmpty(cc))
            mMailMessage.CC.Add(cc);
        mMailMessage.IsBodyHtml = true;
        mMailMessage.Priority = MailPriority.Normal;

        //Sending Mail Message through GMAIL
        var mSmtpClient = new SmtpClient("smtp.gmail.com", 587);
        mSmtpClient.EnableSsl = true;
        mSmtpClient.Credentials = new System.Net.NetworkCredential(from, "GMAIL Password");
        mSmtpClient.Send(mMailMessage);
    }
于 2011-05-22T17:05:22.620 回答
-1

你的标题说明了一切。服务器只允许 TLS 连接。全部解释在这里:https ://www.rfc-editor.org/rfc/rfc2487

于 2011-05-21T09:08:55.710 回答