无法连接到 SMTP 服务器
//aspx.cs file
protected void SendButton_Click(object sender, EventArgs e)
{
MailHelper.SendMailMessage("[email protected]", "[email protected]", "", "", "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)
处遇到错误。
你能帮我吗?
//aspx.cs file
protected void SendButton_Click(object sender, EventArgs e)
{
MailHelper.SendMailMessage("[email protected]", "[email protected]", "", "", "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
}
}
I'm getting error at mSmtpClient.Send(mMailMessage)
.
Could you help me with it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
鉴于发件人地址是 gmail 帐户,我假设您正在尝试通过 GMAIL 发送电子邮件,如果不是,则本地计算机中的 SMTP 服务器有问题。
我希望这有帮助:
Given that the from address is a gmail account i'm assuming you are trying to send an email through GMAIL, if not there is a problem with your SMTP server in the local machine.
I hope this helps:
你的标题说明了一切。服务器仅允许 TLS 连接。
全部解释如下:https://www.rfc-editor.org/rfc/rfc2487
Your title says it all. The server does only allow TLS connections.
All explained here: https://www.rfc-editor.org/rfc/rfc2487