发送邮件不会在实时网站上发送到外部,只能在visual studio调试模式下工作

时间:2014-01-27 15:00:48

标签: c# email iis visual-studio-2012

我遇到了一个奇怪的问题,我的发送邮件功能并没有向外部收件人发送电子邮件。所以我调试了visual studio中的应用程序,并在其中发送了一些断点,它确实发送了电子邮件并收到了它们。

那么现在我如何调试为什么它在实时站点上不起作用而在调试模式下呢?

这是我的发送邮件代码

MailMessage mail = new MailMessage();
mail.From = new MailAddress("internaladdress@domain.com"));
foreach (var Supplier in tblRequest.GroupBy(r => r.SupplierID).OrderBy(g => g.First().tblSuppliers.Supplier))
{
    //mail.Bcc.Add(new MailAddress(Supplier.First().tblSuppliers.EmailAddress));
}
mail.Bcc.Add(new MailAddress("externaladdress@outlook.com"));
mail.Bcc.Add(new MailAddress("internaladdress@domain.com"));
mail.ReplyToList.Add(new MailAddress("internaladdress@domain.com"));
mail.IsBodyHtml = true;
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
SmtpClient client = new SmtpClient();
var SMTPCredentials = new System.Net.NetworkCredential("DOMAIN\\USER", "Password");
client.Credentials = SMTPCredentials;
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Host = "IP ADDRESS OF MAIL SERVER";
mail.Subject = "IS" + intEmailQuoteID.ToString("D5") + " Quote";
//mail.Body += "<html>";
//mail.Body += "<head>";
//mail.Body += "<title></title>";
mail.Body += "<style>body {font-family:calibri;} table {border-collapse:collapse;} table, th, td {border: 1px solid black; padding:10px;}</style>";
//mail.Body += "</head>";
//mail.Body += "<body>";
mail.Body += "<p>Could you please provide us with prices for the below? Any questions please reply to this email address.</p>";
if (tblRequest.First().tblQuotes.EmailNotes != "")
    mail.Body += "<p>" + tblRequest.First().tblQuotes.EmailNotes + "</p>";
mail.Body +="<p>Thank You</p>";
mail.Body += "<table style='width:700px'>";
mail.Body += "<tr>";
mail.Body += "<td style='background:#CCC;'>Quote Reference No:</td>";
mail.Body += "<td>IS" + intEmailQuoteID.ToString("D5") + "</td>";
mail.Body += "<td style='background:#CCC;'>Orginator:</td>";
mail.Body += "<td>" + helpers.GetUserName(tblRequest.First().tblQuotes.OriginatorID) + "</td>";
mail.Body += "<td style='background:#CCC;'>Request Date:</td>";
mail.Body += "<td>" + tblRequest.First().tblQuotes.RequestDate.ToString("dd/MM/yyyy") + "</td>";
mail.Body += "</tr>";
mail.Body += "</table>";
mail.Body += "<br />";
mail.Body += "<table style='width:700px'>";
mail.Body += "<thead>";
mail.Body += "<tr>";
mail.Body += "<th>Quantity</th>";
mail.Body += "<th>Item</th>";
mail.Body += "<th>Part No</th>";
mail.Body += "<th>Description</th>";
mail.Body += "</tr>";
mail.Body += "</thead>";
mail.Body += "<tbody>";
foreach (var mailItem in tblRequest.GroupBy(r => r.ItemID).OrderBy(g => g.First().tblItems.Name))
{
    mail.Body += "<tr>";
    mail.Body += "<td>" + mailItem.First().Quantity + "</td>";
    mail.Body += "<td>" + mailItem.First().tblItems.Name + "</td>";
    mail.Body += "<td>" + mailItem.First().tblItems.PartNo + "</td>";
    mail.Body += "<td>" + mailItem.First().tblItems.Description + "</td>";
    mail.Body += "</tr>";
}
mail.Body += "</tbody>";
mail.Body += "</table>";
//mail.Body += "</body>";
//mail.Body += "</html>";
try
{
    client.Send(mail);
}
catch(Exception ex)
{
    ViewBag.Errors = ex.ToString();
}

此外,内部邮件在实时站点上的调试和实时站点(以及发送通知)中都会收到,我只获得内部信息,而不是外部信息

由于

0 个答案:

没有答案