I have a background program that uses MailMan to send emails through different email servers, depending on the 'From' address. The first email that gets sent when the program starts works fine. When the next email goes through, even though I have used the 'Set ComFrom' command with the new email address, MailMan still uses the first email address when trying to authenticate with the server.
Specifically, the SmtpConn_sendMime_FROM value that is used by MailMan is from the first email, and is not updated with the new address. This will usually cause a '553 From address not verified' error, and the send will fail. If I stop and restart the program, the email will go through fine, but subsequent emails that use a different server will typically fail.
When I use the 'Get ComFrom' command, it does show the correct address. Is there something else I need to do to force MailMan to use the newest 'From' address for the authentication?
Here is the section of code that sets up and sends the email:
Get IsComObjectCreated of oEmail to iCreated If (not(iCreated)) Send CreateComObject of oEmail Set ComSubject of oEmail to sSubject Set ComBody of oEmail to sBody Set ComFrom of oEmail to sFromAddress <--- This correctly sets the new email address Set ComSmtpPassword to sPW Set ComSmtpUsername to sUser Set ComSmtpHost to sServerAddress Send ComDropAttachments of oEmail Send ComClearTo of oEmail Send ComClearCC of oEmail Move (ComAddTo(oEmail,'',sToAddress)) to iRetVal Get pvComObject of oEmail to vEmail Move (ComSendEmail(Self,vEmail)) to iRetVal Get ComLastErrorText to sReturn Get ComCloseSmtpConnection to iRetVal
Here is a snippet of the return value from MailMan:
helloResponse: 250-smtp.mail.yahoo.com 250-PIPELINING 250-SIZE 41697280 250-8 BITMIME 250 AUTH PLAIN LOGIN XYMCOOKIE login_method: LOGIN CONNECTED to ESMTP server smtp.mail.yahoo.com:465 ConnectionType: SSL/TLS checkOrMakeSmtpConnection: Elapsed time: 1156 millisec SmtpConn_sendMime_FROM: email@example.com <--- This address was from the previous email 553 From address not verified Failed when sending MAIL FROM:<firstname.lastname@example.org> 220 smtp.mail.yahoo.com ESMTP ready
It turns out that the problem is with the SendEmail command. It apparently does not reset the fromAddr parameter that is used when the email is actually sent, once it has been initially set. I tried using both the "Set ComFrom" and "Set ComFromAddress" commands to no avail. Is there another command to set the fromAddr?
What finally did work, was to render the email to MIME, and then use the SendMime command, instead of the SendEmail command. This way I could force the fromAddr value to the correct email address, and it would authenticate correctly.