1.以下代碼用QQ郵箱連接方式(SSL),465埠可以正常發送郵件;
2.我另外一個郵箱必須用STARTTLS的連接方式,587埠,才能發送郵件。
請問應該如何修改代碼,發送STARTTLS驗證方式的郵件?
代碼如下:
Sub Emailcdo()
Dim STUl As String
Dim cdoMail As CDO.Message
Set cdoMail = New CDO.Message
STUl = "http://schemas.microsoft.com/cdo/configuration/"
With cdoMail
.BodyPart.Charset = "GB2312"
.from = "[email protected]" '發件人郵箱
.To = "[email protected]" '收件人
.Subject = "測驗郵件" '郵件主題
.TextBody = "test文本(Text)" '純文本的郵件內容
With .Configuration.Fields
.Item(STUl & "smtpserver") = "xxxxxx" 'SMTP服務器
.Item(STUl & "smtpserverport") = 587 'SMTP服務器埠
.Item(STUl & "smtpusessl") = True 'SMTP服務器驗證方式
.Item(STUl & "sendusing") = 2 '使用網路smtp服務器
.Item(STUl & "smtpauthenticate") = 1 '遠程服務器需要驗證
.Item(STUl & "sendusername") = "[email protected]" '發送郵箱賬號
.Item(STUl & "sendpassword") = "xxx" '發送郵箱密碼
.Item(STUl & "smtpconnectiontimeout") = 60 '連接超時(秒)
.Update
End With
On Error GoTo err
.Send
End With
MsgBox "郵件發送成功!", 64, "發送成功"
Set cdoMail = Nothing
Exit Sub
err:
Set cdoMail = Nothing
MsgBox "郵件發送失敗" & err.Number & err.Description, 48, "錯誤提示"
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/11938.html
標籤:VBA
下一篇:無效的程序呼叫或引數
