简体   繁体   English

C#asp.net System.Net.Mail未收到传出电子邮件

[英]C# asp.net System.Net.Mail outgoing emails not recieved

I'm using System.Net.Mail and I'm trying to send an email (to myself actually) to some address. 我正在使用System.Net.Mail ,正在尝试将电子邮件(实际上是发给自己)发送到某个地址。 I belive I'm setting it up correctly and I'm getting no exceptions thrown but the mail isn't delivered?! 我相信我正在正确设置它,并且没有引发任何异常,但邮件未送达? I have no clue as to what's going on. 我不知道发生了什么事。 I have no messages, errors, no indication of a problem. 我没有消息,错误,没有问题的迹象。 Here's my code: 这是我的代码:

using System.Net.Mail;

EmailSender email = new EmailSender();

email.From = "steve_kershaw@yahoo.com";
email.Subject = "Test email!";
email.To = "Steve.Kershaw@securitynational.com";
email.Body = "An event just occured.";
email.SendMail();

And in a separate class I have: 在单独的课程中,我有:

mMailMessage.Subject = strSubject;
mMailMessage.Body = strBody;
mMailMessage.IsBodyHtml = true;
mMailMessage.Priority = MailPriority.Normal;

// Send the message.
SmtpClient mSmtpClient = new SmtpClient(strHost);
mSmtpClient.Send(mMailMessage);

I've stepped through this code countless times but everything seems normal. 我无数次地遍历了这段代码,但是一切似乎都很正常。 Can anybody help?! 有人可以帮忙吗?

Your code looks fine to me. 您的代码对我来说很好。 Check out your SmtpClient configuration. 检查您的SmtpClient配置。

There is a cool blog post about Sending Email with System.Net.Mail . 有一篇很酷的博客文章,关于Sending Email with System.Net.Mail Your SmtpClient should look like this; 您的SmtpClient应该看起来像这样;

<system.net>
    <mailSettings>
      <smtp from="steve_kershaw@yahoo.com">
        <network host="smtpserver1" port="25" userName="username" password="secret" defaultCredentials="true" />
      </smtp>
    </mailSettings>
  </system.net>

This may be elementary, but also ensure the smtp service is running. 这可能是基本的,但也要确保smtp服务正在运行。 Had several occasions where the code was correct but emails did not deliver because of that very simple thing. 曾经有几次代码是正确的,但是由于那件事很简单,电子邮件却没有送达。

May also be worthwhile to restart the smtp service 重新启动smtp服务可能也值得

I had an issue where everything looked correct but the mail wasn't sending. 我遇到了一个问题,其中的一切看起来都正确,但是邮件未发送。 No errors or exceptions. 没有错误或异常。 The problem was my 'From address'. 问题是我的“发件人地址”。 I had picked a made up address like: 'do-not-reply@ThisAppsName.com' Turns out, the server realised that wasn't an address and didn't send the mail. 我选择了一个伪造的地址,例如:'do-not-reply@ThisAppsName.com'事实证明,服务器意识到这不是地址,也没有发送邮件。 I changed it to an email address of the App's owners dis list and all went fine. 我将其更改为应用程序所有者dis列表的电子邮件地址,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM