Help with VBA code for email without Outlook

Perpa

Well-known Member
Joined
Dec 18, 2012
Messages
654
I searched and followed the following link on Mr Excel:
http://www.mrexcel.com/forum/excel-questions/649148-email-userform-without-outlook.html

Refers to: email without outlook: http://www.rondebruin.nl/cdo.htm
Which provided code and tips which I have tried...

In the line of code below I use my correct 'password':
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"

I have tried both '25' and '465' in the following line of code:
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
'465' is the correct port, but I get the following VB error message:

"Run-time error '=2147220973 (80040213)': The transport failed to connect to the server."

The code appears to run fine right up until the error message appears. When I look at 'Debug'
to see where the code stopped it is on the line...'.Send' in the 'With' statement.
I have tried using Cox and gmail with the same result.

Have I missed something in the code, or where else might I look to sort this out?
My goal is to get this code to work, then modify it to send a pdf attachment.
I am using Windows 7 and Excel 2007.
Thank you in advance for any help.
Perpa

Code:
Sub CDO_Mail_Small_Text()
    Dim iMsg As Object
    Dim iConf As Object
    Dim strbody As String
    Dim Flds As Variant

    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")

    iConf.Load -1    ' CDO Source Defaults
    Set Flds = iConf.Fields
    With Flds
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "capopat48@gmail.com"
        .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
        .Update
    End With

    strbody = "Hi there" & vbNewLine & vbNewLine & _
              "This is line 1" & vbNewLine & _
              "This is line 2" & vbNewLine & _
              "This is line 3" & vbNewLine & _
              "This is line 4"

    With iMsg
        Set .Configuration = iConf
        .To = "perpa48@gmail.com"
        .CC = ""
        .BCC = ""
        .From = "capopat48@gmail.com"
        .Subject = "New figures"
        .TextBody = strbody
        .Send
    End With

End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
yky
I am using Cox for my ISP, but I also have Gmail.
I tried using the code you sent in Cox "smtp.coxmail.com"
I entered the line of code you suggested and tried it in two locations but received the same error code both times:

Error Code: "Run-time error '-214722095 (80040211)':
The message could not be sent to the SMTP server. The transport error code was 0x80040217.
The server response was not available."

This error came up right away, no delay as with the previous error message.

The first try was the blank line, the second try is highlighted in red:

Code:
    With Flds
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        [COLOR="#FF0000"].Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True[/COLOR]
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.coxmail.com"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
        '
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username@cox.net"
        .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypassword"
        .Update
    End With

mas123 - I will try your suggestion using the less secure Gmail option and see if that works. However I would like to
get this Cox portion working if possible.

Thank you both so much for your prompt responses and suggestions.

Perpa
 
Upvote 0
mas123 - I tried gMail with the new line from yky and it worked without using the less secure option.

I would still like to get the' SMTP.coxmail.com' working if possible. Any ideas??

Thank you both for looking at this. Now at least I have the gmail option working without Outlook!
That is a BIG help. Many, Many thanks.
Perpa
 
Upvote 0
Perhaps you need to ask your ISP.
 
Upvote 0
yky,
I'll do that. Thank you for your help, and also thanks to mas123.
Perpa
 
Upvote 0
yky,
I did some digging on the Cox website and it turns out that

.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.coxmail.com"
Should be:
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.cox.net"

And the correct port is 25:
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

I made those two changes and it worked like a charm!

Thanks again for your help!

Perpa
 
Upvote 0
Solution

Forum statistics

Threads
1,214,589
Messages
6,120,416
Members
448,960
Latest member
AKSMITH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top