Sending mail through a remote SMTP server

deadseasquirrels

Board Regular
Joined
Dec 30, 2004
Messages
232
I've been trying to send emails through an SMTP server in various ways. I've been able to send email using CDO going directly through an SMTP server on my same local network (not requiring a username and password). But now I am trying to send email from my home with the SMTP server I am using that is hosted by some commercial company. I used the code below, which is sponsored by Paul Sadowski:
Code:
Sub sendMailRemote()
    'Sending a text email using authentication against a  remote SMTP server

    Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
    Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
    Const cdoAnonymous = 0 'Do not authenticate
    Const cdoBasic = 1 'basic (clear-text) authentication
    Const cdoNTLM = 2 'NTLM
    
    Dim objMessage As Object

    Set objMessage = CreateObject("CDO.Message")
    objMessage.Subject = "Example CDO Message"
    objMessage.Sender = """Me"" <me@my.com>"
    objMessage.To = "me@hotmail.com"
    objMessage.TextBody = "This is some sample message text.." & vbCrLf & "It was sent using SMTP authentication."

    '==This section provides the configuration information for the remote SMTP server.

    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

    'Name or IP of Remote SMTP Server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.myserver.com"

    'Type of authentication, NONE, Basic (Base64 encoded), NTLM
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

    'Your UserID on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "deadesasquirrels"

    'Your password on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "squirrels"

    'Server port (typically 25)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

    'Use SSL for the connection (False or True)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True

    'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

    objMessage.Configuration.Fields.Update

    '==End remote SMTP server configuration section==

    objMessage.Send

End Sub

So this code doesn't work. It says "Transport failed to connect to server" which is pretty general. But the thing is I do use the SMTP server from outlook, so port 25 is not blocked, I'm positive I am using the correct username and password (again, because outlook works). Also I know the SMTP server requires authentication...so I'm not sure what else is wrong. If Mr. Sadowski is on this forum maybe you can reply as well. Anybody have any experience with this?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Well I tried it and this time it didn't throw an error, but the email didn't send either, it just went into never neverland. Can somebody try the code above and let me know if they get different results?
 
Upvote 0
I am trying to get it to work now... and I cant...?

Im trying to use it off of the gmail server...

My code is :

-----

Sub sendMailRemote()
'Sending a text email using authentication against a remote SMTP server

Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM

Dim objMessage As Object

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.Sender = """Me"" <me@my.com>"
objMessage.To = "test@gmail.com"
objMessage.TextBody = "This is some sample message text.." & vbCrLf & "It was sent using SMTP authentication."

'==This section provides the configuration information for the remote SMTP server.

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"

'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "email@gmail.com"

'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

objMessage.Send

End Sub


-----

Can you help me by any chance?
 
Upvote 0
Found this, but still isnt working... I did change the server port to both 465 and 587, but neither seem to work?

Incoming Mail (POP3) Server - requires SSL: pop.gmail.com
Use SSL: Yes
Port: 995

Outgoing Mail (SMTP) Server - requires TLS: smtp.gmail.com (use authentication)
Use Authentication: Yes
Use STARTTLS: Yes (some clients call this SSL)
Port: 465 or 587

Account Name: your Gmail username (including '@gmail.com')
Email Address: your full Gmail email address (username@gmail.com)
Password: your Gmail password
 
Upvote 0
Hi,

Now it's time for me ;)
The same problem, the same error.

What is the key that will get it work?
 
Upvote 0
Thanks for reply... :]

Since Sunday I've already run it in the case of gmail... But, I have still a problem while using a smtp server on SSL but not on 465 but 25 port...

There is a standard exception: Transport failed to connect to server...
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,582
Members
449,089
Latest member
Motoracer88

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