2

I've been trying to figure out what I'm doing wrong for a considerable amount of time and still no avail. I was wondering if anyone here could recognise whether there's something noticeably incorrect with the following.

I'm setting up relaying via SMTP, starting out in a C# .net service, where I'm sending a message via SMTP to PowerMTA, I'm using the following to do so:

    MailMessage msg = new MailMessage();
    SmtpClient client = new SmtpClient("12.345.678.90", 25);

    client.Credentials = new NetworkCredential("myUsername", "myPassword");

    msg.Body = "<html><head></head><body><h1>Hello World</h1></body></html>";
    msg.To.Add("recipient@adomain.com");
    msg.From = new MailAddress("sender@mydomain.com", "Sender");
    msg.IsBodyHtml = true;
    msg.Subject = "Local Relay Test";

    client.Send(msg);

Here's a snippet from my PowerMTA configuration, that corresponds to my sent message:

<smtp-user myUsername>  
  password myPassword
  source {auth}  
</smtp-user>

<source {auth}>
    always-allow-relaying yes    # allow feeding for defined users
    process-x-virtual-mta yes    # allow selection of a VirtualMTA
    max-message-size 0           # 0 implies no cap, in bytes
    smtp-service yes             # allow SMTP service
    default-virtual-mta myVmta
    require-auth true
    log-connections yes
    log-commands    yes         # WARNING: verbose!
</source>

I also have a general source 0/0 with logging turned on and always-allow-relaying set to no.

When I run through my code I get the following exception:

An unhandled exception of type 'System.Net.Mail.SmtpFailedRecipientException' occurred in System.dll

Additional information: Mailbox unavailable. The server response was: 5.7.1 relaying denied: <recipient@adomain.com> in "RCPT TO:<recipient@adomain.com>"

Although when I view the logs in PowerMTA, it seems to hit my general rule of 0/0 and not the {auth} source. There is absolutely no sign of a username and password being passed across. Am I missing something obvious?

I've also tested this locally on the server where PowerMTA is hosted, it just hits the 0/0 source and not the {auth} source again.

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Lloyd Powell
  • 18,270
  • 17
  • 87
  • 123
  • Maybe the client thinks it can use default credentials. Did you try setting `UseDefaultCredentials` to `false` (before setting `Credentials`) to see if this has any impact? – Christoph Sommer Jul 29 '15 at 09:24

1 Answers1

2

PMTA will generate 5.7.1 relaying denied rejections if the IP you're connecting from is not defined in a <source> directive that allows SMTP relaying. Add something like this to your config:

<source 1.2.3.4/24>
    always-allow-relaying yes
    smtp-service yes
</source>

It can be useful to do manual SMTP tests outside of your code; I've found swaks to be the best tool for this (at least on Linux systems) - http://www.jetmore.org/john/code/swaks/

evan_b
  • 1,079
  • 1
  • 11
  • 22