Sending Email SMTP setting (1 Viewer)

Local time
Today, 08:22
Joined
Oct 7, 2016
Messages
43
Dear Sir,

The Below mentioned VBA Access Code is working in Windows 11 O/s but the same is not working in Windows 7 O/S.
Similarly respective setting of Email Accounts of different Operating System i.e Windows 11 O/s & Windows 7 O/s is attached here as Image.


Unable to send the Email , We are getting an Run-time error '-2147220973 (80040213)''
"The Transport failed to connect to server."


I tried to change the SMTP setting from 465 to 587 , but it is not working.
Please suggest the VBA code to change the SSL Setting.
or
Please correct the code to send email.


Sub SendMail()
Dim objEmail

Dim objMail As Object

Const cdoSendUsingPort = 2 ' Send the message using SMTP
Const cdoBasicAuth = 1 ' Clear-text authentication
Const cdoTimeout = 60 ' Timeout for SMTP in seconds

mailServer = "ambassadorindia.icewarpcloud.in"
SMTPport = 465
mailusername = "ABC@ambassadorindia.com"
mailpassword = "******"


mailto = "anandan.cr@gmail.com"
mailSubject = "test : " & Now()



mailBody = "Dear Sir/Madam," & vbCrLf & _
"" & vbCrLf & _
" Please find attached Salary Slip " & vbCrLf & _
" For the month of " & vbCrLf & _
" " & vbCrLf & _
" Regards" & vbCrLf & _
" " & vbCrLf & _
" HR Department" & vbCrLf & _
" " & vbCrLf & _
" " & vbCrLf & _
" Company Name" & vbCrLf & _
" This Salary Slip is password protected.The password is 8-character password - combination of the first four letters of your name in CAPITAL( as it is mentioned in your Personal File kept in HR) and the date and month of your Date of Birth(DOB) ( as updated in our records) " & vbCrLf & _
" " & vbCrLf & _
" For instance, " & vbCrLf & _
" If your name is C.R.Anandan and your DOB(DD-MMM-YYYY) is 01-FEB-1991 then the password would be C.R.0102 " & vbCrLf & _
" If your name is CRAnandan and your DOB(DD-MMM-YYYY) is 01-FEB-1991 then the password would be CRAN0102 " & vbCrLf & _
" " & vbCrLf


Set objEmail = CreateObject("CDO.Message")
Set objConf = objEmail.Configuration
Set objFlds = objConf.Fields

With objFlds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailServer
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPport
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = cdoTimeout
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasicAuth
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailusername
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailpassword
.Update
End With

objEmail.To = mailto
objEmail.From = mailusername
objEmail.Subject = mailSubject
objEmail.TextBody = mailBody
objEmail.AddAttachment "d:\Report.pdf"
objEmail.Send

Set objFlds = Nothing
Set objConf = Nothing
Set objEmail = Nothing
End Sub



Email_Err_PERASST.png

Mail_Setting_WIN-11.png
 
So why not match the settings on the win7 computer to those on the win11 computer?
That is what I would do.

Very rare for a sever not to use SSL these days I would have thought.
 
Sending mails via SMTP from VBA is a tricky thing regarding ports and protocols.
To get a deep insight I would suggest to read Philipps article well.

Additionally I would expect that all this belongs to the servers setting an not to the clients.
So I wonder why there is a difference in behaviour of the same code between Win7 and Win11.
Maybe it is a firewall setting on Win7 which blocks the connection?
 
Last edited:
You could use Colin's app to test your settings.

Personally, I would enable SSL on incoming and outgoing.

That is not the only page you should check either?
1709986533600.png
 
The only other obvious difference I could see would depend on each workstation's routing tables. If you can open the CMD prompt on each system, you can issue a simple command to examine the routing tables on each machine and compare them.
Code:
ROUTE /?                       - to see the commands available on each system.
ROUTE PRINT                 - to see the current system's routing tables.

Each version of Windows approaches the CMD window differently. For Win10, it is Start >> Windows System >> Command Prompt ... but I don't remember what you use for Win7 and I don't have Win11. You need to know the NUMERIC address of your mail server (let's say it is 103.161.42.81, see below for how I know that). Using the ROUTE PRINT command, you would look for the IPv4 table. You look for at least one routing table entry to contain a "Network Destination" address (first column of IPv4 table) that looks like 103.161.42.255 OR 103.161.255.255 - i.e. last part or last two parts = 255 - but if the failing server does NOT have a routing entry with that destination, it is a routing issue and you need to add the appropriate address. It would be rare but not impossible to have 103.255.255.255 and that would also be OK for your purposes.

By the way, you show the mail server this way in your code:
Code:
MailServer = "ambassadorindia.icewarpcloud.in"
Therefore, while you are in the CMD prompt, you can find the IP address with
Code:
PING ambassadorindia.icewarpcloud.in

Pinging ambassadorindia.icewarpcloud.in [103.161.42.81] with 32 bytes of data:
Reply from 103.161.42.81: bytes=32 time=289ms TTL=44
Reply from 103.161.42.81: bytes=32 time=232ms TTL=44
Reply from 103.161.42.81: bytes=32 time=305ms TTL=44
Reply from 103.161.42.81: bytes=32 time=327ms TTL=44

I'm with AHeyne in that it is not likely to be the SMTP settings. It is more likely a Windows or network setup issue. You can test this simply by using that PING command. If you can't ping it by name OR by address from the CMD prompt, you won't be able to send mail through it.
 
You could use Colin's app to test your settings.

Personally, I would enable SSL on incoming and outgoing.

That is not the only page you should check either?
View attachment 112977


Done ,tried with setting in CDO Email Tester

it work with setting :

SMTP PORT : 587
SSL : FALSE



\Please suggest the VBA code to change the SSL Setting to false
or
Please correct the code to send email using SMTP PORT : 587 , SSL : FALSE
Attached is the sample
 

Attachments

  • ssl.png
    ssl.png
    53 KB · Views: 99
  • Working_wd_SSL_FALSE.png
    Working_wd_SSL_FALSE.png
    100.6 KB · Views: 116
Done ,tried with setting in CDO Email Tester

it work with setting :

SMTP PORT : 587
SSL : FALSE



\Please suggest the VBA code to change the SSL Setting to false
or
Please correct the code to send email using SMTP PORT : 587 , SSL : FALSE
Attached is the sample

Based on the attachment that was successful sending the email, change the configuration settings to the below and it should work.

Code:
With objFlds

    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "ambassadorindia.icewarpcloud.in"
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "yourEmail"
    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourPassword"
   
    .Update
   
End With
 

Users who are viewing this thread

Back
Top Bottom