Link to home
Start Free TrialLog in
Avatar of habs_2005
habs_2005

asked on

cdo - windows 2000 - adding message headers

I have been trying to change the following in cdo - return-path, and add message header.  When I use the following code I end up with 2 different return-paths and a header is not added.

Dim objCfg
    set objCfg = server.CreateObject("CDO.Configuration")
Dim objCfgFlds
    set objCfgFlds = objCfg.Fields

with objCfgFlds
        .Item(cdoSendUsingMethod) = cdoSendUsingPort  
            .item(cdoSMTPServerPort) = 8025
            .Item(cdoSMTPServer) = "127.0.0.1"  
  .Item("urn:schemas:mailheader:X-Mailer")  = "Microsoft CDO testing change"
  .item("urn:schemas:mailheader:return-path") = "bounce@test.com"
  .item("urn:schemas:mailheader:sender") = "nc@test.com"
  .update
End with

response.Write(now())
response.Write(" it ends on ..")

Dim objMail
 set objMail = server.CreateObject("CDO.Message")

  with objMail
   .Configuration = objCfg   .From = "natacha@onroad.com"
      .To = "from@test.com"
        .Subject = "Sample CDO Message"  
        .TextBody = "This is a test for CDO.message"  
   .Send
  End with
Set objMail = nothing

Please point me in the right direction :)
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

From our friend Sajit:

' ** SUBROUTINE TO SEND EMAIL USING CDOSYS **

'**USAGE **
'strMailBody="<Font Color=Red><B>Test HTML String</B></Font>"
'CALL SendMailCDOSYS("a@b.com","c@d.com","test",strMailBody,True,"mail.yahoo.com")

Sub SendMailCDOSYS(strFrom,strTO,strSubject,strMailBody,blnHTML,sMailServer)
On Error Resume Next
     Dim objCDOConf,objCDOSYS
     ' ** CREATE THE E-MAIL SERVER OBJECT **
     Set objCDOSYS = Server.CreateObject("CDO.Message")
     Set objCDOConf = Server.CreateObject ("CDO.Configuration")

     ' ** SET AND UPDATE FIELDS PROPERTIES **
     With objCDOConf
          ' ** OUT GOING SMTP SERVER **
          .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sMailServer
          ' ** SMTP PORT **
          .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport")  = 25
          ' ** CDO PORT **
          .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
          ' ** TIMEOUT **
          .Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
          .Fields.Update
     End With

     ' ** UPDATE THE CDOSYS CONFIGURATION **
     Set objCDOSYS.Configuration = objCDOConf

     With objCDOSYS    
          ' ** WHO THE E-MAIL IS FROM **
          .From = strFrom

          ' ** WHO THE E-MAIL IS SENT TO **
          .To = strTo
                   
          ' ** THE SUBJECT OF THE E-MAIL **
          .Subject = strSubject
           
          ' ** SET THE E-MAIL BODY FORMAT (HTMLBody=HTML TextBody=Plain) **
          If blnHTML = True Then
          .HTMLBody = strMailBody
          Else
          .TextBody = strMailBody
          End If
           
          ' ** SEND THE E-MAIL **
          .Send
     End with                    
       
     ' ** CLOSE THE SERVER MAIL OBJECT **
     Set objCDOSYS = Nothing
End Sub
ASKER CERTIFIED SOLUTION
Avatar of ap_sajith
ap_sajith

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ap_sajith
ap_sajith

Ideally you should modify the above subroutine to take in the additional parameters required for the custom headers. So that you can reuse the subroutine throughout your code..

Cheers!!

Avatar of habs_2005

ASKER

Thanks for the solutions - I just have a few more questions before I accept an answer.

ap_sajith - I have copied your code and tested it on my local server.  It does change the header and I can create a new customer header as well.  The only strange thing that is does is creates 2 return-paths - the first one set is the sender and the second one is the one I tried to set.  Any idea why this might happen?

Also - is there a reason you use the following format:
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sMailServer

instead of .Fields(cdoSMTPServer) = sMailServer

Thanks again!!
>>The only strange thing that is does is creates 2 return-paths - the first one set is the sender and the second one is the one I tried to set.  Any idea why this might happen?<<

I did try it at my side and it was returning just one return path. Maybe it is some setting in your mail server.

As for using
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sMailServer

instead of .Fields(cdoSMTPServer) = sMailServer,

I do not have the CDO  typelyb included. So i will have to do away with the CDO constants.

Cheers!!
Thanks again ap_sajith !!

I will have to speak to our sys admin - we are just using the smtp server in windows 2000.  Hopefully he can figure out what the problem with the return path might be.

Grade B?. Any particular reason for a lower grade?.

Cheers!!
Please let me know if there is any reason why you gave the solution a Grade of 'B'... Otherwise, i might have to ask one of th emoderators to review the grading.

Thanks!
I gave a B because your answer did not solve my entire problem.  If you want a moderator to review - please feel free.  I cannot seem to change your grade myself.
Its ok... If you felt that my answer wasnt complete, then i must accept it... Thanks for the reply though.

Cheers!!