Home > Software engineering >  [for] when using email cdo STARTTLS way secure connection
[for] when using email cdo STARTTLS way secure connection

Time:11-08

1. The following code using QQ email connection (SSL), the port 465 can be normal email;
2. Must I use another email the STARTTLS connections, port 587, can send mail,

Excuse me, how should modify the code, send email STARTTLS validation way?

The code is as follows:
 Sub Emailcdo () 
Dim STUl As String
Dim cdoMail As cdos. Message
The Set cdoMail=New CDO. Message
STUl="http://schemas.microsoft.com/cdo/configuration/"
With cdoMail
. BodyPart. Charset="GB2312"
.="[email protected]" 'from the sender email address
To the recipient
="[email protected]" '. The Subject="test email" '
email Subject. TextBody="test Text (Text)" 'plain Text content
With the Configuration. The Fields
The Item (STUl & amp; "Smtpserver")="XXXXXX" 'SMTP server
The Item (STUl & amp; "Smtpserverport")=587 'SMTP server port
The Item (STUl & amp; "Smtpusessl")=True 'SMTP server authentication way
The Item (STUl & amp; "Sendusing")=2 'using the network SMTP server
The Item (STUl & amp; "Smtpauthenticate")=1 'on the remote server requires authentication
The Item (STUl & amp; "Sendusername")="[email protected]" 'send E-mail account
The Item (STUl & amp; "Sendpassword")="XXX" 'send email password
The Item (STUl & amp; "Smtpconnectiontimeout")=60 'connection timeout (in seconds)
. The Update
End With
On Error GoTo err
. Send
End With
MsgBox "mail sent successfully!" , 64, "send success
"The Set cdoMail=Nothing
The Exit Sub
Err:
The Set cdoMail=Nothing
MsgBox "mail delivery failure" & amp; Err. Number & amp; Err, Description, 48, "error"
End Sub


  •  Tags:  
  • VBA
  • Related