【发布时间】:2015-10-27 17:14:38
【问题描述】:
我正在开发一个网络应用程序,计划向新成员发送确认电子邮件。我是使用 ASPET 开发电子邮件服务的新手。该应用程序运行时没有错误或异常,并且显然在 try 和 catch 块返回异常时发送电子邮件。但是,甚至没有人收到一封邮件。这是代码:
using System;
using System.Net;
using System.Web;
using System.Net.Mail;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Text.RegularExpressions;
public void SendEmailAddressVerificationEmail(string Username, string To)
{
MEFManager.Compose(this);
string encryptedName = Username.Encrypt("verify");
string msg = "Please click on the link below or paste it into a browser to verify your email account.<BR><BR>" +
"<a href=\"" + _configuration.RootURL + "Account/VerifyEmail.aspx?a=" +
encryptedName + "\">" +
_configuration.RootURL + "Account/VerifyEmail.aspx?a=" +
encryptedName + "</a>";
SendEmail(To, "", "", "Account created! Email verification required.", msg);
}
public void SendEmail(string To, string CC, string BCC, string Subject, string Message)
{
MailMessage mm = new MailMessage(FROM_EMAIL_ADDRESS,To);
if(!string.IsNullOrEmpty(CC))
mm.CC.Add(CC);
if (!string.IsNullOrEmpty(BCC))
mm.Bcc.Add(BCC);
mm.Subject = Subject;
mm.Body = Message;
mm.IsBodyHtml = true;
Send(mm);
}
private void Send(MailMessage Message)
{
try
{
//During developement we will not be sending mails
#if !DEBUG
SmtpClient smtp = new SmtpClient();
smtp.Send(Message);
Console.Write("E-mail sent!");
#endif
}
catch(Exception ex)
{
Console.Write("Could not send the e-mail - error: " + ex.Message);
}
}
web.config 和 web.release.config 文件如下:
Web.config:
<system.net>
<mailSettings>
<smtp>
<network host="localhost" port="25" defaultCredentials="true"/>
</smtp>
</mailSettings>
</system.net>
web.release.config:
<smtp from="postmaster@itok.com">
<network
host="mail.itok.com"
defaultCredentials="true"
enableSsl="false"
port="25"
userName="postmaster@itok.com"
password="*********"
xdt:Transform="Replace"
/>
</smtp>
谁能帮我找出原因?有没有人有想法或建议在哪里寻找答案?这种问题的根源可能是什么?
【问题讨论】: