我有代码,
System.Web.Mail.MailMessage oMailMessage = new MailMessage();
oMailMessage.From = strFromEmaild;
oMailMessage.To = strToEmailId;
oMailMessage.Subject = strSubject;
oMailMessage.Body = strBody;
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(oMailMessage);
Run Code Online (Sandbox Code Playgroud)
(所有变量都有值)
我已经安装了SMTP虚拟服务.为什么它无法发送电子邮件.为什么不工作?
编辑
public bool SendMail(string strToEmailId, string strFromEmaild, string strSubject, string strBody)
{
try
{
System.Web.Mail.MailMessage oMailMessage = new MailMessage();
oMailMessage.From = strFromEmaild;
oMailMessage.To = strToEmailId;
oMailMessage.Subject = strSubject;
oMailMessage.Body = strBody;
SmtpMail.SmtpServer = "SERVERNAME";
SmtpMail.Send(oMailMessage);
return true;
}
catch (Exception ex)
{
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
我有这个代码.它正在执行正常并返回true,但我没有在收件箱中收到任何电子邮件.
我发现邮件只能发送到Gmail帐户......为什么会这样?
确定错误是什么:
try
{
SmtpMail.Send(oMailMessage);
}
catch (Exception ex)
{
//breakpoint here to determine what the error is:
Console.WriteLine(ex.Message);
}
Run Code Online (Sandbox Code Playgroud)
从这里,请使用异常详细信息编辑您的问题。
| 归档时间: |
|
| 查看次数: |
2701 次 |
| 最近记录: |