电子邮件不发送,没有错误? [英] email not sending, no errors?

查看:120
本文介绍了电子邮件不发送,没有错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这个简单的code尝试和发送电子邮件:

I'm using this simple code to try and send an email:

    try
    {
        MailMessage newMail = new MailMessage();
        newMail.To.Add("me@mydomain.com");
        newMail.Subject = "test";
        newMail.Body = "test";
        newMail.From = new MailAddress("from@mydomain.com", "from");
        newMail.IsBodyHtml = true;

        SmtpClient SmtpSender = new SmtpClient();
        SmtpSender.Send(newMail);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }

随着我的web.config文件下面code:

along with the below code in my web.config file:

<system.net>
<mailSettings>
  <smtp>
    <network host="localhost" userName="me@mydomain.com" password="password" defaultCredentials="true"/>
  </smtp>
</mailSettings>

我运行该页面,并没有错误完成,但没有发送电子邮件。我在做什么错了?

I run the page and it completes with no errors, but no email is sent. What am I doing wrong?

编辑:我根据很多例子,我看了看,并与现在使用称为hMailServer本地SMTP客户端更新code。我测试过我的hMailServer ASP.Net之外,它确实发送电子邮件。但是,使用新的code以上仍不能正常工作,并不会引发任何异常。

I've updated the code according to the many examples I've looked at and and am now using a local SMTP client called hMailServer. I've tested my hMailServer outside of ASP.Net and it does indeed send emails. However, using the new code above it still does not work and does not throw any exceptions.

推荐答案

如果您在别处托管电子邮件的形式,可能需要医达是谁做你的窗体上发送。

If you are hosting your email form elsewhere, you may need to "doctor up" who is doing the sending on your form.

GoDaddy的,为一体,将阻止,他们认为是高垃圾邮件源(如Gmail,Hotmail和雅虎邮件)特定域的电子邮件。

GoDaddy, for one, will block emails from certain domains that they consider to be high SPAM sources (like GMail, Hotmail, and Yahoo! Mail).

要解决此问题,从您的域名,preferably假的起源的电子邮件地址发送邮件,以便不会开始得到吨的垃圾邮件:

To work around this, send your message from an email address that originates on your domain, preferably a fake one so you won't start getting tons of spam:

private const string mailer = "no-reply@yourDomain.com";

继续前进,code在您的网站管理员的地址,好措施:

Go ahead and code in your webmaster address, for good measure:

private const string webmaster = "yourEmail@yourDomain.com";

在构建您的电子邮件,你的联系人的电子邮件地址应该被指定在回复字段(从 txtEmail.Text 在$下面C $ C):

When constructing your email message, your contact's email address should be specified in the Reply-To field (from txtEmail.Text in the code below):

lblError.Text = null;
using (var email = new System.Net.Mail.MailMessage(
  new MailAddress(mailer), new MailAddress(webmaster)) {
  email.ReplyTo = txtEmail.Text; // this comes off of your contact form
  string strHtmlBody =
    "<html><body style=\"background-color:#cccccc\">" +
    txtSubject.Text +
    "</body></html>";
  email.Subject = "Website Contact";
  email.Body = strHtmlBody;
  email.IsBodyHtml = true;
  var server = new SmtpClient("relay-hosting.secureserver.net");
  try {
    server.Send(email);
  } catch (Exception err) {
    lblError.Text = err.Message;
  }
}

这篇关于电子邮件不发送,没有错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆