【问题标题】:Gmail not receiving certain messages, are showing up in sent folderGmail 未收到某些邮件,显示在已发送文件夹中
【发布时间】:2014-07-13 13:15:02
【问题描述】:

我正在尝试在系统完成付款处理后向自己发送电子邮件通知。我正在使用以下代码:

public Exception SendEmail(string subject, string body)
    try
    {
        var fromAddress = new MailAddress(Setting.Get("smtp_from"), Setting.Get("smtp_from_name"));
        var toAddress = new MailAddress(Setting.Get("smtp_to"), Setting.Get("smtp_to"));

        var smtp = new SmtpClient
        {
            Host = Setting.Get("smtp_host"),
            Port = Int32.Parse(Setting.Get("smtp_port")),
            EnableSsl = true,
            DeliveryMethod = SmtpDeliveryMethod.Network,
            Credentials = new NetworkCredential(fromAddress.Address, Setting.Get("smtp_password")),
            Timeout = Int32.Parse(Setting.Get("smtp_timeout"))
        };
        using (var message = new MailMessage(fromAddress, toAddress)
        {
            Subject = subject,
            Body = body
        })
        {
            smtp.Send(message);
        }

        return null; //All went well
    }
    catch (Exception ex)
    {
        return ex;
    }
}

没有什么特别之处,只是通过 Google 找到的基本代码。此代码与以下消息和主题完美配合:

Subject: [SUCCESS] Donation processed successfully
Message: This is a test.

但是,当消息变成这样时:

Donation received and processed successfully! No further action is required.
Donor: John Doe
Donation amount: 4,00 EUR
Email: fake@user.com
Mandrill API Response: Sent

我的收件箱中没有任何内容。它确实显示在发送电子邮件的帐户的已发送项目中。我已经检查了所有内容,垃圾邮件,thrash,但它就是没有到达。

有没有人遇到过这种情况?有谁知道如何解决这个问题?

【问题讨论】:

    标签: c# email gmail mandrill


    【解决方案1】:

    这对我来说非常适合:

     public static void SendEmail(string emailbody)
        {
          MailMessage mailMessage = new MailMessage("incoming email address", "receiver email address");
          mailMessage.Body = emailbody;
          mailMessage.Subject = "Feedback";
    
          SmtpClient smtpClient = new SmtpClient("relay-hosting.secureserver.net", 25);
          smtpClient.EnableSsl = false;
          smtpClient.Send(mailMessage);
        }
    

    希望对你有帮助

    【讨论】:

    • 内容可以单独添加到邮件正文中。例如string Contents = "Donation received and processed successfully! No further action is required. Donor: John Doe Donation amount: 4,00 EUR Email: fake@user.com Mandrill API Response: Sent"; 然后:SendEmail(Contents);
    • 函数以这些为参数调用。
    【解决方案2】:

    好的,我找到了问题。

    看看这个:

    using (var message = new MailMessage(fromAddress, toAddress)
    {
        Subject = subject,
        Body = body
    })
    {
        smtp.Send(message);
    }
    

    using 语句在调用 .Send(message) 方法之前处理 MailMessage,并且由于某种原因这不会产生异常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-08
      • 2016-07-12
      • 1970-01-01
      • 2013-08-26
      • 2014-10-20
      • 2021-01-19
      相关资源
      最近更新 更多