Search code examples
asp-classicsmtpmessaging

Using classic ASP, is it possible to set the SMTP envelope from address with CDO?


I am sending mail using classic ASP with the CDOSYS objects, but I would like the envelope from address - that is, the one that is specified by MAIL FROM during SMTP - to be set differently to the From header address in the message.

The purpose of this is to implement VERP. For example, I would expect the SMTP dialogue to be something like:

220 mail.example.com ESMTP
[...]
MAIL FROM: <info+test=example.com@mydomain.test>
250 2.0.0 OK
RCPT TO: <test@example.com>
250 2.0.0 OK
DATA
354 Start mail input; end with <CRLF>.<CRLF>
From: Company1 <info@mydomain.test>
To: test@example.com
[...]

In the above example, the envelope from is "info+test=example.com@mydomain.test" but the From header is "info@mydomain.test".

Hope this makes sense. Any ideas?


Solution

  • ok I got it figured out and I wiresharked it and I see the commands as you want them...

    Sorry about the horrible answer I gave you before. This will do it... it is the "SENDER" that you want for the MAIL FROM: envelope

    Const cdoSendUsingPort = 2
    StrSmartHost = "localhost"
    
    set iMsg = CreateObject("CDO.Message")
    set iConf = CreateObject("CDO.Configuration")
    
    With iConf.Fields 
    .item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort 
    .item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSmartHost 
    .Update 
    End With 
    
    
    
    
    With iMsg
    Set .Configuration = iConf
    .To = "test@example.com"
    .Sender = "info+test=example.com@mydomain.test"
    .From="Company1 <info@mydomain.test>"
    .Subject = "This is a test CDOSYS message (Sent via Port 25)..."
    .HTMLBody = strHTML
    .Send
    End With