bluetickk
bluetickk

Reputation: 689

System.Net.Mail.SmtpException: Mailbox unavailable

// CREATE NEW EMAIL OBJECT
ContactUs.Core.Email oEmail = new ContactUs.Core.Email();

// EMAIL SMTP SERVER INFORMATION
oEmail.SmtpServer = "Server";
oEmail.SetAuthentication("Email", "Password");

// EMAIL INFORMATION
oEmail.From = "[email protected]";
oEmail.To = "RecipientEmail";
oEmail.Subject = this.txtMessage.Text;
oEmail.Message = strMessage;

// SEND EMAIL
oEmail.HtmlFormat = true;
oEmail.Send();

This is the error I am getting. I know that the authentication is correct.

System.Net.Mail.SmtpException: Mailbox unavailable. The server response was: 5.7.1 Client does not have permissions to send as this sender
at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at ContactUs.Core.Email.Send()
at _Default.btnSend_Click(Object sender, EventArgs e)

Upvotes: 1

Views: 31235

Answers (3)

Alice
Alice

Reputation: 1265

you have to set username in the SMTP Authentication as [email protected].

        // CREATE NEW EMAIL OBJECT
        ContactUs.Core.Email oEmail = new ContactUs.Core.Email();

        // EMAIL SMTP SERVER INFORMATION
        oEmail.SmtpServer = "Server";
        oEmail.SetAuthentication("[email protected]", "Password");

        // EMAIL INFORMATION
        oEmail.From = "[email protected]";
        oEmail.To = "RecipientEmail";
        oEmail.Subject = this.txtMessage.Text;
        oEmail.Message = strMessage;

        // SEND EMAIL
        oEmail.HtmlFormat = true;
        oEmail.Send();

Your SMTP Server doesn't allow you to set Credential username different from oEmail.From (e-mail address of Sender).

Upvotes: 1

user240141
user240141

Reputation:

Add Network credentials to your code.

Sample Mail Code:

private void SendMailViaGmailUsingCredentials()
        {
            try
            {
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                mail.From = new MailAddress("[email protected]");
                mail.To.Add("[email protected]");
                mail.Subject = "Test Mail";
                mail.Body = "This is for testing SMTP mail from GMAIL";

                SmtpServer.Port = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
                SmtpServer.EnableSsl = true;

                SmtpServer.Send(mail);
                MessageBox.Show("mail Send");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
}

Upvotes: 0

Aaron Barker
Aaron Barker

Reputation: 706

5.7.1 == relaying prohibited

You need to allow relaying for authenticated users, or from a range of IPs from your SMTP server: http://support.microsoft.com/kb/304897

What kind of server are you using to relay the messages?

Upvotes: 2

Related Questions