我收到異常,因爲問題而在asp.net發送電子郵件C#
郵箱名稱不允許的。服務器的迴應是:對不起,您的 信封發件人在我的badmailfrom列表中。
下面是發送電子郵件的代碼
public void SendEmail()
{
try
{
string Smtp_Client = System.Configuration.ConfigurationManager.AppSettings["Smtp_Client"];
string NewtwrkCredentials_Uname = System.Configuration.ConfigurationManager.AppSettings["NewtwrkCredentials_Uname"];
string NewtwrkCredentials_P = System.Configuration.ConfigurationManager.AppSettings["NewtwrkCredentials_P"];
//Declaration a list of attendees
MailAddressCollection macCollection = new MailAddressCollection();
//Add attendde. In this example, I send invite to only one
macCollection.Add(new MailAddress("****@****.com"));
//Create mail message
MailMessage mmMessage = formMailMessage("Test", "Test", "***.***@gmail.com", macCollection);
//Create smtp client
SmtpClient smtp = new SmtpClient("smtpout.europe.secureserver.net", 25);
//Configure your smtp client
smtp.EnableSsl = false;
smtp.Credentials = new NetworkCredential("****@*****.com", "****");
//Send it
smtp.Send(mmMessage);
}
catch (Exception er)
{
}
}
public static MailMessage formMailMessage(string strSubject, string strBodyHTML, string Email, MailAddressCollection macAttendeeList)
{
//Create an instance of mail message
MailMessage mmMessage = new MailMessage();
// Set up the different mime types contained in the message
System.Net.Mime.ContentType typeText = new System.Net.Mime.ContentType("text/plain");
System.Net.Mime.ContentType typeHTML = new System.Net.Mime.ContentType("text/html");
AlternateView viewHTML = AlternateView.CreateAlternateViewFromString(strBodyHTML, typeHTML);
mmMessage.AlternateViews.Add(viewHTML);
//Adress the message
mmMessage.From = new MailAddress(Email);
foreach (MailAddress attendee in macAttendeeList)
{
mmMessage.To.Add(attendee);
}
mmMessage.Subject = strSubject;
return mmMessage;
}
任何人都可以幫助我的代碼,以什麼我做錯了什麼?我創建了一個控制檯應用程序,並使用相同的代碼,它工作正常。 smtp服務器,網絡憑據都是正確的。
好心幫
再試一次其他發件人。這是服務器的問題,它不允許指定的發件人。 – looper
可能是一個很好的參考:http://stackoverflow.com/questions/10282602/system-net-mail-smtpfailedrecipientexception-mailbox-name-not-allowed –
當前的發送者是在服務器黑名單,嘗試另一種發件人。 – sajanyamaha