C# .NET - The server rejected one me recipient addresses. The server response was: 530 SMTP auntication is required asp.net

Asked By Manoj Pandey on 08-Jan-10 01:48 AM
Hello..
I am using asp.net to send email
I am using mail server as mail say 'mail.xyz.com'
It was working earlier and was successfully sending emails..
but one day suddenly it started giving error messages
 "The server rejected one or more recipient addresses. The server response was: 530 SMTP authentication is required"

I have replaced original mail server name with random ....but here i am using a valid mail server,, and it was working very well earlier...
my function is as follows:

public bool SendEmails(string pTo, string pSubject, string pBody, System.Web.Mail.MailFormat pFormat, string pAttachmentPath)
        {
            try
            {
                string pGmailEmail = "info@thexyz.com";
                System.Web.Mail.MailMessage myMail = new System.Web.Mail.MailMessage();
                myMail.From = pGmailEmail;
                myMail.To = pTo;
                myMail.Subject = pSubject;
                myMail.BodyFormat = pFormat;
                myMail.Body = pBody;
                if (pAttachmentPath.Trim() != "")
                {
                    MailAttachment MyAttachment = new MailAttachment(pAttachmentPath);
                    myMail.Attachments.Add(MyAttachment);
                    myMail.Priority = System.Web.Mail.MailPriority.High;
                }

                System.Web.Mail.SmtpMail.SmtpServer = "mail.xyz.com";
                System.Web.Mail.SmtpMail.Send(myMail);
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

Any help ?

See this - Kalit Sikka replied to Manoj Pandey on 08-Jan-10 02:01 AM

This is happening because your SmtpMail.SmtpServer is rejecting addresses.
  • Make sure all email addresses specified at MailMessage.To, MailMessage.Cc, MailMessage.Bcc and MailMessage.From are valid email addresses.
  • Make sure you have permissions to relay through the server.
  • Make sure the MailMessage.From has permissions to relay through the server.

re - Web Star replied to Manoj Pandey on 08-Jan-10 02:05 AM

This error comes due to authentication problem u need to provide uid/pwd for $SMTP server as follows

The following example demonstrates sending your username and password to the SMTP server to provide authentication.

private void Page_Load(object sender, System.EventArgs e)
{
 MailMessage mail = new MailMessage();
 mail.To = "me@mycompany.com";
 mail.From = "you@yourcompany.com";
 mail.Subject = "this is a test email.";
 mail.Body = "Some text goes here";
 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here"); //set your username here
 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret"); //set your password here

 SmtpMail.SmtpServer = "mail.mycompany.com";  //your real server goes here
 SmtpMail.Send( mail );
}

530 SMTP authentication error - mv ark replied to Manoj Pandey on 08-Jan-10 02:09 AM

To authenticate while sending an email using System.Web.Mail, use this snippet - http://www.systemwebmail.com/faq/3.8.aspx

If you are working on .NET 2.0 or above, use the classes in System.Net.Mail as they are more efficient. For the corresponding snippet that utilizes System.Net.Mail, check this - http://www.systemnetmail.com/faq/4.2.aspx

If you have to send email over SSL, check this - http://www.systemnetmail.com/faq/4.5.aspx

Re - Huggy Bear replied to Manoj Pandey on 08-Jan-10 02:14 AM
Since it was working fine earlier and from the error message I suspect it could be a cause of below reasons

1. Email Ids provided by you in To, Bcc or CC is not of a valid format.
2. If all are valida formats, then the SMTP server doesn't have the persmission to relay the emails to some domains of few email addresses.

Please check for this condition. I would say that there is nothing to worry about your C# code for sending emails.
Reply.... - Manoj Pandey replied to Web Star on 08-Jan-10 02:15 AM
Yes...I can add that to work.. but how is it possible that it was working earlier with the same function as is posted here..
without any authentication it was working and i was sending mails successfully ..i checked myself..
Today only it started giving that Authentication error...
Could it be due to changes in mail server settings???
I am not aware about any changes made to mail server...is it possible?