Reputation: 13
I am sending mails using our company SMTP server. I get the problem when I am sending mail to other mails (out side of the company domain), returning the error:
"The server rejected one or more recipient addresses. The server response was 550 5.7.1 unable to relay".
If the mail is within the company, then there is no error and mail sending successfully. My web application hosted in IIS.
Upvotes: 0
Views: 22907
Reputation: 747
I have Solved this problem. For using this code you need to add the namespace Using System.Web.Mail;
Source Code:
MailMessage mail = new MailMessage();
mail.To = "[email protected]";
mail.From = "[email protected]";
mail.Subject = "Email test.";
mail.Body = "Your body text 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 = "127.0.0.1";
SmtpMail.Send( mail );
//your need to add localhost address to IIS Manager. Goto IIS Manager -> Default SMTP Server ->Properties -> Access -> Relay -> allow only from the list below -> add -> 127.0.0.1 -> Click OK
Upvotes: 1
Reputation: 17960
I'll assume that there is nothing wrong in your code. I guess it is a configuration issue i.e SMTP server configured to not send emails to addresses that are not part of your company domain. If so you need to check with your Windows/Network team to confirm configuration applied at SMTP server level.
Upvotes: 1