电子邮件未发送到Gmail,Yahoo,Hotmail

时间:2014-10-06 15:55:23

标签: c# asp.net email

我正在尝试从使用C#/ ASP.NET编写的Web应用程序发送电子邮件。

我正在尝试发送电子邮件的HTML和文本版本。 但是,当我尝试发送到Gmail,Yahoo,Hotmail,AOL等电子邮件地址时,它不会显示在收件箱中。

当我严格发送文字时,如果没有HTML备用视图,它就可以正常发送。

这里有没有人有这方面的经验?

电子邮件已妥善发送至我们的托管Exchange服务器" @ mxxx.com"

谢谢!

编辑:还有一件事。当电子邮件无法送达时,我们不会收到任何类型的失败递送通知,它基本上会消失。

代码:

// email the user
                MailMessage message = new MailMessage("support@mxxx.com", user.EmailAddress);
                message.Bcc.Add("xxx@gmail.com");
                message.Bcc.Add("xxx@yahoo.com");
                message.Bcc.Add("xxx@hotmail.com");
                message.Subject = "Your \"mxxx.com\" password has been reset";
                message.ReplyToList.Add(new MailAddress("support@mxxx.com"));
                message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure | DeliveryNotificationOptions.Delay |
                                                      DeliveryNotificationOptions.OnSuccess;
                message.Sender = new MailAddress("support@mxxx.com");

                string htmlbody = "<html><body><p>Dear " + name + ":</p>" +
                "<p>Your password at \"mxxx.com\" has been reset to: " + newPassword + "</p>" +
                </body></html>";

                var plainTextBody = "test plain text";

                AlternateView plainTextView =
                    AlternateView.CreateAlternateViewFromString(
                        plainTextBody, message.BodyEncoding, MediaTypeNames.Text.Plain);

                plainTextView.TransferEncoding = TransferEncoding.Base64;
                message.AlternateViews.Add(plainTextView);

                AlternateView htmlview =
                    AlternateView.CreateAlternateViewFromString(
                        htmlbody, message.BodyEncoding, MediaTypeNames.Text.Html);

                htmlview.TransferEncoding = TransferEncoding.Base64;

                message.AlternateViews.Add(htmlview);



                SmtpClient mailMan = new SmtpClient();
                mailMan.Send(message);

1 个答案:

答案 0 :(得分:0)

如果您避免使用AlternateView并指定正文是HTML,该怎么办? 考虑测试下一个片段?:

            MailMessage message = new MailMessage("support@mxxx.com", user.EmailAddress);
            message.Bcc.Add("xxx@gmail.com");
            message.Bcc.Add("xxx@yahoo.com");
            message.Bcc.Add("xxx@hotmail.com");
            message.Subject = "Your \"mxxx.com\" password has been reset";
            message.ReplyToList.Add(new MailAddress("support@mxxx.com"));
            message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure | DeliveryNotificationOptions.Delay |
                                                  DeliveryNotificationOptions.OnSuccess;
            message.Sender = new MailAddress("support@mxxx.com");

            string htmlbody = "<html><body><p>Dear " + name + ":</p>" +
            "<p>Your password at \"mxxx.com\" has been reset to: " + newPassword + "</p>" +
            </body></html>";

            message.Body = htmlbody;
            message.IsBodyHtml = true;
            SmtpClient mailMan = new SmtpClient();
            mailMan.Send(message);