0

我想使用 asp.net 发送电子邮件,我已经配置了我的 SMTP 服务并添加了 127.0.0.1 作为中继。我以前在家里申请成功了,但是我在办公室安装它不能发送电子邮件,为什么?

这是C#代码

MailMessage objemail = new MailMessage();
objemail.To.Add(new MailAddress("apthodisiac@gmail.com"));
objemail.From = new MailAddress(Request.Form["inputEmail"].ToString());
objemail.Subject = Request.Form["inputSubject"].ToString();
objemail.Body = "Dari: " + Request.Form["inputName"].ToString() + "\n\n" +
                "Phone: " + Request.Form["inputPhone"].ToString() + "\n\n" +
                Request.Form["inputMsg"].ToString();
objemail.IsBodyHtml = true;
objemail.Priority = MailPriority.Normal;

SmtpClient objSmtpClient = new SmtpClient();
objSmtpClient.Send(objemail);

这是 web.config 配置

<system.net>
<mailSettings>
  <smtp deliveryMethod="Network">
    <network host="127.0.0.1" port="25" userName="yyyy" password="xxxxx" />
  </smtp>
</mailSettings>
</system.net>

我的办公室使用代理,是我无法发送电子邮件的问题吗?请指教

4

2 回答 2

0

可能是端口号错误尝试使用端口号"587"如下所示:

private void SendEmail(string from, string to, string subject, string body)
    {
      MailMessage mail = new MailMessage(new MailAddress(from), new MailAddress(to));

      mail.Subject = subject;
      mail.Body = body; 

      SmtpClient smtpMail = new SmtpClient("smtp.gmail.com");
      smtpMail.Port = 587;
      smtpMail.EnableSsl = true;
      smtpMail.Credentials = new NetworkCredential("xxx@gmail.com", "xxx");
      // and then send the mail
      smtpMail.Send(mail);
    }
于 2012-11-08T08:40:15.683 回答
-1

你可以试试这个:

objSmtpClient.EnableSsl = true
于 2012-11-08T08:31:40.550 回答