0

I would like to ask for advice how to solve a problem i am having with my mail server.

I have

I have a problem to send emails from my mail server using my web sites.

every time i am trying to sendemail from my site i get this error:

Mailbox unavailable. The server response was: Authentication is required for relay

can anybody advice me how to fix it in a way that all emails thas are going out from my web server are allowed to be send.

My Code Fro Sending Email is :

MailMessage MyMailMessage = new MailMessage();
MyMailMessage.From = new MailAddress("xxx@gmail.com");
MyMailMessage.To.Add("xxx@gmail.com");
MyMailMessage.Subject = "Inquiry Form";
MyMailMessage.IsBodyHtml = true;
MyMailMessage.Body = "Hello";
SmtpClient SMTPServer = new SmtpClient("mail.DomainName.com");
 SMTPServer.Port = 25;
 SMTPServer.Credentials = new NetworkCredential("UserName", "Password");
SMTPServer.EnableSsl = false;
 SMTPServer.Send(MyMailMessage);

Also i have code in Web.config file :

 <system.net>
<mailSettings>
  <smtp from="mail.domainname.com">
    <network host = "mail.domainname.com" userName ="xxxxx" password= "xxxxx" />
  </smtp>
</mailSettings>

Nikunj
  • 307
  • 3
  • 12
  • 2
    Possibly `mail.domainname.com` doesn't let you send email as `xxx@gmail.com` when you are authenticating as another user. Some servers only let you send mail "from" the person who is authenticated. – MikeSmithDev Dec 04 '13 at 14:49
  • Is this on a shared web server (i.e. hostgator or bluehost)? Or an intranet site (corporate) – webdad3 Dec 04 '13 at 14:50
  • Check if there's an option in account settings that lets you list the ports and applications it accepts connection from. – nstosic Dec 04 '13 at 14:51
  • How are you retrieving **UserName** and **Password** from web.config? – Win Dec 04 '13 at 14:54
  • gmail doesn't listen on port 25. See the following question: http://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail – NotMe Dec 04 '13 at 14:57

1 Answers1

-1

When you set up your mail server, did you ensure the username you are using in the web.config is setup on the server? Looks like the server is unable to authenticate your request.

Sash
  • 3,525
  • 3
  • 19
  • 17