I am getting the exception as
Mailbox name not allowed. The server response was: Sorry, your envelope sender is in my badmailfrom list.
Here is the code to send the email
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;
}
Can anyone help me with the code as to what am i doing wrong? i created a console application and used the same piece of code and it worked fine. the smtp server, network credentials are all proper.
Kindly Help
Pretty much what the error says the from address is in a black list of email addresses.
If you have a system administrator who manages the server contact them to resolve this, or use another address to send it from.
If it's a hosted service contact the provider and notify them and ask them what credentials to use.
不知道问题出在哪里,我使用了不同的smtp服务器,并且代码正常工作。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.