我得到了例外
不允许使用邮箱名称。服务器响应是:对不起,您的信封发件人在我的 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 服务器,网络凭据都正确。
请帮助