Change FROM address for Sending Email - VBscript

Hello,

I am using the below sample script which I have found on EE to send emails. I am trying to change the from address in the script, but its not being sent from the FROM address given, its sending the from the same as its connecting to the server, ie: sEmailAddress

Can someone please advise?
Thanks

 

Sub SendEmail(sSubject, sEmailText, sEmailAddress, sPassword, sTo, sCCEmailAddress, sAttachment)
    Set oEmail = CreateObject("CDO.Message")

    oEmail.From = "test@test.com"
    oEmail.To = sTo
    oEmail.CC = sCCEmailAddress
    oEmail.AddAttachment sAttachment
    oEmail.Subject = sSubject
    oEmail.HTMLbody = sEmailText

    sSchema = "http://schemas.microsoft.com/cdo/configuration/"
    oEmail.Configuration.Fields.Item(sSchema & "sendusing") = 2
    oEmail.Configuration.Fields.Item(sSchema & "smtpserver") = "smtp.test.com"
    oEmail.Configuration.Fields.Item(sSchema & "smtpserverport") = 465
    oEmail.Configuration.Fields.Item(sSchema & "smtpauthenticate") = 1
    oEmail.Configuration.Fields.Item(sSchema & "sendusername") = sEmailAddress
    oEmail.Configuration.Fields.Item(sSchema & "sendpassword") = sPassword
    oEmail.Configuration.Fields.Item(sSchema & "smtpusessl") = 1
    oEmail.Configuration.Fields.Item(sSchema & "smtpconnectiontimeout") = 60
    oEmail.Configuration.Fields.Update
    oEmail.Send

    Set oEmail = Nothing
End Sub

Open in new window

LVL 6
charlie324Asked:
Who is Participating?
 
sammySeltzerCommented:
Oops, sorry. I think I gave you .net code.
Should be something like this:

oEmail.From = """Test"" <test@test.com>"
0
 
sammySeltzerCommented:
Try:

oEmail.From = New Net.Mail.MailAddress("test@test.com")
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.