locked
Excel VBA code for sending email over SMTP server using CDO - no longer appearing in my Outlook.com Sent Email folder RRS feed

  • Question

  • I have had some excel VBA code I have been using to automate some email notifications I need to send to colleagues and associates on a regular basis. It has worked fine for over a year.

    I use CDO to send the emails over an SMTP server.

    My email account provider uses Outlook.com as the webmail for my email account.

    When I first wrote the code I noticed that the emails would appear in my Sent folder which was nice because I like to have a record of the emails I sent.

    My code is still working but last week the emails stopped appearing in my Outlook.com sent folder.

    I tried a different port but only port 25 seems to work.

    I actually don't understand anything about SMTP servers or CDO ... I just copied the code from the internet and it was all working fine.

    As a temporary work around, I am simply cc'ing myself, but I was curious if anybody can explain what might have caused this to happen.... whether it is purely an Outlook.com issue or something to do with my SMTP server? Has a bug arisen in Outlook.com? Or could there be a flaw in my code that was only revealed after many months of running fine.


    • Edited by batkis Thursday, September 17, 2015 6:46 PM explain question better
    Wednesday, September 16, 2015 2:20 PM

Answers

  • >>>what might have caused this to happen.... whether it is purely an Outlook.com issue or something to do with my SMTP server? Has a bug arisen in Outlook.com? Or could there be a flaw in my code that was only revealed after many months of running fine.

    Base on your description, I suggest that you could use or apply another Outlook.com account to make sure whether Outlook.com or VBA code cause this issue.

    Otherwise if you have a GMail account, you could run your VBA code to make sure whether you could reproduce this issue.

    You could refer to below code:

    Sub SendMail()
    
        Set MyEmail = CreateObject("CDO.Message")
    
        MyEmail.Subject = "Subject"
    
        MyEmail.To = "junfeng_dai@163.com"
    
        MyEmail.TextBody = "Testing one two three."
    
        Set emailConfig = MyEmail.Configuration
    
    
        emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    
        emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
    
        emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    
        emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    
        emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    
        emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your username@gmail.com"
    
        emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "you password"
    
        emailConfig.Fields.Update
    
        MyEmail.Configuration.Fields.Update
    
        MyEmail.Send
    
        Set MyEmail = Nothing
    
    End Sub
    


    For more information, click here to refer about Configuration CoClass

    • Proposed as answer by David_JunFeng Thursday, September 24, 2015 1:19 AM
    • Marked as answer by Fei XueMicrosoft employee Tuesday, September 29, 2015 2:37 AM
    • Unmarked as answer by batkis Saturday, October 10, 2015 9:22 PM
    • Marked as answer by batkis Saturday, October 10, 2015 10:25 PM
    Friday, September 18, 2015 8:26 AM

All replies

  • >>>what might have caused this to happen.... whether it is purely an Outlook.com issue or something to do with my SMTP server? Has a bug arisen in Outlook.com? Or could there be a flaw in my code that was only revealed after many months of running fine.

    Base on your description, I suggest that you could use or apply another Outlook.com account to make sure whether Outlook.com or VBA code cause this issue.

    Otherwise if you have a GMail account, you could run your VBA code to make sure whether you could reproduce this issue.

    You could refer to below code:

    Sub SendMail()
    
        Set MyEmail = CreateObject("CDO.Message")
    
        MyEmail.Subject = "Subject"
    
        MyEmail.To = "junfeng_dai@163.com"
    
        MyEmail.TextBody = "Testing one two three."
    
        Set emailConfig = MyEmail.Configuration
    
    
        emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    
        emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
    
        emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    
        emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    
        emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    
        emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your username@gmail.com"
    
        emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "you password"
    
        emailConfig.Fields.Update
    
        MyEmail.Configuration.Fields.Update
    
        MyEmail.Send
    
        Set MyEmail = Nothing
    
    End Sub
    


    For more information, click here to refer about Configuration CoClass

    • Proposed as answer by David_JunFeng Thursday, September 24, 2015 1:19 AM
    • Marked as answer by Fei XueMicrosoft employee Tuesday, September 29, 2015 2:37 AM
    • Unmarked as answer by batkis Saturday, October 10, 2015 9:22 PM
    • Marked as answer by batkis Saturday, October 10, 2015 10:25 PM
    Friday, September 18, 2015 8:26 AM
  • Thanks very much for your reply David. I have just continued to cc myself as a workaround. I was able to use your code (after adding a "from" field which was missing from your code)  to send an email from my microsoft email account. Again there is nothing appearing in the sent folder and this occurs on more than one Microsoft email account.I had to temporarily change some security setting in my gmail to get your code to work with a gmail account. I suspect that Microsoft has changed their settings for outlook.com email to prevent the email sent from CDO from appearing in the sent folder.


    • Edited by batkis Saturday, October 10, 2015 10:25 PM update
    Saturday, October 10, 2015 9:18 PM