首页 > 解决方案 > VBA 取消发送由 Gmail 发送的电子邮件

问题描述

我知道 Google Gmail 是一个可以在 30 秒内取消已发送电子邮件的功能。

当我使用此代码从访问数据库和通过 gmail 发送电子邮件时,我想知道是否有办法使用该功能来防止发送错误的电子邮件?

Sub SendEmail_Click()
Dim NewMail As CDO.Message
Set NewMail = New CDO.Message

'Enable SSL Authentication
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True

'Make SMTP authentication Enabled=true (1)

NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

'Set the SMTP server and port Details
'To get these details you can get on Settings Page of your Gmail Account

NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"

NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

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

'Set your credentials of your Gmail Account

NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "mysite@gmail.com"

NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypassword7"

'Update the configuration fields
NewMail.Configuration.Fields.Update

'Set All Email Properties

With NewMail
Dim strPath As String
strPath = ".mysite/wp-content/uploads/2017/07/myimage.png"
.subject = "this is the subject"
.From = "<mail@mysite.com>"
.To = Me.EMAIL
'.CC = ""
'.BCC = ""
.HTMLBody = "This is my message body"
.AddAttachment "https://mysite/temp/contacts.vcf"
End With

NewMail.Send
MsgBox ("This email was sent!")

'Set the NewMail Variable to Nothing
Set NewMail = Nothing

End Sub

标签: ms-accessvbagmailms-access-2007

解决方案


推荐阅读