0

i am creating an email client that sends e-mail address from server ip instead of SMTP , i wrote that code:

SmtpClient server = new SmtpClient("50.23.128.66");
MailMessage msg = new MailMessage("from@yahoo.com", "tome@yahoo.com", "subject", "body");
server.Send(msg);

but when i run it , i get that error:

Unhandled Exception: System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Relaying Denied. at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressColl ection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)

* By the way i am using Windows Server 2008 * and i configured the smtp server to localhost and port 25 , but i don`t know what is that relying error .

R.Vector
  • 1,669
  • 9
  • 33
  • 41
  • When you send a `someone@foo.com` email through an `bar.com` SMTP server, you are using the `bar.com` server as a mail relay. If the `bar.com` server is not configured to relay mail, it will reject SMTP attempts that aren't part of its own domain, or users on it. In other words this is not a programming error, but a server error, and you should check with the server configuration. Perhaps better suited to serverfault.com. – Adam Davis Jan 16 '12 at 18:59

2 Answers2

3

If you are using you localhost to rely email, you should be using 127.0.0.1 or localhost instead of that ip address you posted in your code.

Icarus
  • 63,293
  • 14
  • 100
  • 115
  • yes , but i have 3 ips on that server and i want to switch ips when sending emails , so that i dont be a spammer – R.Vector Jan 16 '12 at 19:08
  • 2
    Who said that by switching ips you won't be flagged as a spammer? It's more complicated than that. – Icarus Jan 16 '12 at 19:12
1

Relaying is the method the SMTP server uses to authenticate that it should route the email from a particular sender. An "open relay" means that there is no authentication and the SMTP server will send email sent from anyone. This is not a good practice and there are probably some mechanisms on this particular SMTP server to authenticates, such as a user name and password or even the IP address of the sender. Check with the administrator of the SMTP server to see what is required. I would think at a minimum you would need to set the user name and password, which you did not do in your code example.

Kevin Junghans
  • 17,475
  • 4
  • 45
  • 62