1

I am trying to send a mail from admin@bitcoindk.dk to hejmeddig@gmail.com by doing this:

    MailMessage mailObj = new MailMessage();
    mailObj.From = new MailAddress("admin@bit.dk");
    mailObj.To.Add("hejmeddig@gmail.com");
    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="admin@bitcoindk.dk">
        <network host="mail.bitcoindk.dk" port="25" userName="admin@bitcoindk.dk" password="password"  />
      </smtp>
    </mailSettings>
  </system.net>

When i send the mail, i get this exception

Transaction failed. The server response was: 5.7.1 <hejmeddig@gmail.com>: Relay access denied

If i send a mail to admin@bit.dk, it works fine. But if i send to hejmeddig@gmail.com, 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("google@gmail.com"));
SmtpClient client = new SmtpClient(cfg.Network.Host);
client.Send(objMessage);

Web.config

<mailSettings>
    <smtp from="fromemail@mydomain.com">
         <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