VBS to send mail through Office365

Home Forums Scripting Windows Script Host VBS to send mail through Office365

This topic contains 13 replies, has 5 voices, and was last updated by Avatar Anonymous 3 years, 7 months ago.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • Avatar
    hilsoe
    Participant
    #166057

    I need a script to send mail from event viewer through Office 365

    I have this script, when running it nothing happens.

    Public Function SendEmail()

    Set MyEmail = CreateObject(“CDO.Message”)

    MyEmail.Subject = “VBS test mail”
    MyEmail.From = “Office365 sender”
    MyEmail.To = “Receipient”
    MyEmail.TextBody = “this is a test message”

    MyEmail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2

    ‘SMTP Server
    MyEmail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserver”) = “smtp.office365.com”

    ‘SMTP Port
    MyEmail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 587
    MyEmail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpauthenticate”) = cdoBasic
    MyEmail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpusessl”) = True
    MyEmail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/sendusername”) = “Office 365 login account”
    MyEmail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/sendpassword”) = “Office365 password”

    ‘Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
    MyEmail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout”) = 60
    MyEmail.Configuration.Fields.Update

    MyEmail.Send

    Set MyEmail = Nothing

    End Function

    [/CODE]
    [CODE] Public Function SendEmail()

    Set MyEmail = CreateObject(“CDO.Message”)

    MyEmail.Subject = “VBS test mail”
    MyEmail.From = “Office365 sender”
    MyEmail.To = “Receipient”
    MyEmail.TextBody = “this is a test message”

    MyEmail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2

    ‘SMTP Server
    MyEmail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserver”) = “smtp.office365.com”

    ‘SMTP Port
    MyEmail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 587
    MyEmail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpauthenticate”) = cdoBasic
    MyEmail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpusessl”) = True
    MyEmail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/sendusername”) = “Office 365 login account”
    MyEmail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/sendpassword”) = “Office365 password”

    ‘Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
    MyEmail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout”) = 60
    MyEmail.Configuration.Fields.Update

    MyEmail.Send

    Set MyEmail = Nothing

    End Function

    [/CODE]

    tehcamel
    tehcamel
    Moderator
    #360103

    did you write it, or get it from somewhere else?

    Avatar
    Anonymous
    #376673

    I got it from the web. What has that got to do with it?

    tehcamel
    tehcamel
    Moderator
    #360108

    I’m curious. you may need to setup a relay:
    http://technet.microsoft.com/en-us/library/dn554323(v=exchg.150).aspx

    Avatar
    Anonymous
    #376675

    The relay is already there, just need a vb script to do the job.

    tehcamel
    tehcamel
    Moderator
    #360110

    have you tested/confirmed access to port 587 from the host whre this runs?

    Avatar
    Anonymous
    #376676

    Yes that has been confirmed.

    JeremyW
    JeremyW
    Moderator
    #271414

    Did you edit the variables for your environment?

    Avatar
    Anonymous
    #376677

    Yes of cause I did.

    Avatar
    wullieb1
    Moderator
    #245392

    Try using port 25 and not 587. Apparently CDO isn’t supported.

    10. Custom applications that use the Outlook MAPI library typically can connect to Exchange Online, but those that use the Exchange Server MAPI Client and Collaboration Data Objects (MAPI/CDO) for server-to-server communication with Exchange will not connect;

    http://letsexchange.blogspot.com.au/2011/07/office-365-limitations.html

    Avatar
    Anonymous
    #376680

    Have tried both ports, cannot get it to Work.

    Avatar
    wullieb1
    Moderator
    #245394

    try adding dim MyEmail[/CODE] as the first line.

    Will try and test today.[CODE]dim MyEmail[/CODE] as the first line.

    Will try and test today.

    Avatar
    wullieb1
    Moderator
    #245395

    and another thing i’ve found is that the smtpserver should be your pod server rather than smtp.office365.com

    http://forums.devshed.com/visual-basic-programming-52/outlook365-com-sending-email-963102.html

    Avatar
    Anonymous
    #376684

    I have dropped the vbs script, found a powershell script that Works.

Viewing 14 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic.