1

I am trying to send a mail from [email protected] to [email protected] by doing this:

    MailMessage mailObj = new MailMessage();
    mailObj.From = new MailAddress("[email protected]");
    mailObj.To.Add("[email protected]");
    mailObj.Body = "HEJ";
    mailObj.Subject = "HEJ";

    SmtpClient SMTPServer = new SmtpClient();
    SMTPServer.Send(mailObj);

In my web.config, i have this:

  <system.net>
    <mailSettings>
      <smtp from="[email protected]">
        <network host="mail.bitcoindk.dk" port="25" userName="[email protected]" password="password"  />
      </smtp>
    </mailSettings>
  </system.net>

When i send the mail, i get this exception

Transaction failed. The server response was: 5.7.1 <[email protected]>: Relay access denied

If i send a mail to [email protected], it works fine. But if i send to [email protected], or any other mail, i get the exception. I am using Uno Euro's mail service.

Steffan Pallesen
  • 140
  • 1
  • 15

2 Answers2

1

This is what I use to send emails. See if something like this might help solve your problem.

SmtpSection cfg = NetSectionGroup.GetSectionGroup(WebConfigurationManager.OpenWebConfiguration("~/web.config")).MailSettings.Smtp;
MailMessage objMessage = new MailMessage();
objMessage.IsBodyHtml = true;
objMessage.From = new MailAddress(cfg.From);
objMessage.Subject = "Some Subject";
objMessage.Body = sb.ToString();
objMessage.To.Add(new MailAddress("[email protected]"));
SmtpClient client = new SmtpClient(cfg.Network.Host);
client.Send(objMessage);

Web.config

<mailSettings>
    <smtp from="[email protected]">
         <network host="mail.mydomain.com" port="25" userName="mydomain.com" password="myPassword" />
    </smtp>
</mailSettings>
Lucky Pierre
  • 570
  • 4
  • 18
  • What version of IIS are you using? Try out what this guy did too. http://stackoverflow.com/questions/3165721/mailbox-unavailable-the-server-response-was-5-7-1-unable-to-relay-for-abcxyz – Lucky Pierre Apr 10 '13 at 16:13
0

I was using the wrong outgoing mail server.

Steffan Pallesen
  • 140
  • 1
  • 15