问题描述
我复制了一些代码以通过 Gmail 从 Excel 发送电子邮件并不断收到相同的错误: 错误:sendusing 配置值无效。 -2147220960
我看过这个问题的其他答案,这些答案对其他人有效,但对我无效。这可能是因为我在 Gmail 中使用了 2 阶段身份验证? 如果是这样,有没有办法解决这个问题?如果没有,任何人都可以提出前进的道路吗?我对基本的 VBA 相当有能力,但在这方面不擅长。
代码是:
Option Explicit
Sub Emailer()
Dim newMail As cdo.message
Dim mailconfiguration As CDO.Configuration
Dim msConfigURL As String
Dim fields As Variant
On Error GoTo errHandler
Set newMail = New cdo.message
Set mailconfiguration = New CDO.Configuration
mailconfiguration.Load -1
Set fields = mailconfiguration.fields
With newMail
.Subject = "Odd Sock Cottage Bookings"
.From = "dnwigg@gmail.com"
.To = "dnwigg@gmail.com"
.CC = ""
.BCC = ""
.TextBody = "Here's the latest booking list."
.AddAttachment "C:\Users\David\Desktop\Odd Sock Cottage\Visitor instructions\Odd Sock Cottage Location and Parking COVID-19.pdf"
End With
msConfigURL = "http://schemas.microsoft.com/cdoCconfiguration"
With fields
.Item(msConfigURL & "/smtpusessl") = 1
.Item(msConfigURL & "smtpauthenticate") = 2
.Item(msConfigURL & "/smtpserver") = "smtp.gmail.com"
.Item(msConfigURL & "/smtpserverport") = 465
.Item(msConfigURL & "/sendusing") = 2
.Item(msConfigURL & "/sendusername") = "dnwigg@gmail.com"
.Item(msConfigURL & "/sendpassword") = "password"
.Update
End With
newMail.Configuration = mailconfiguration
newMail.Send
MsgBox "Email sent.",vbinformation
exit_line:
Set newMail = nothing
Set mailconfiguration = nothing
Exit Sub
errHandler:
MsgBox "Error: " & Err.Description & Err,vbinformation
GoTo exit_line
Exit Sub
End Sub
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)