我正在尝试使用VBA通过Gmail发送pdf文档。
此代码会发送附带pdf的电子邮件。当我打开附件的pdf时,我看到一个空白页面。我可以看到pdf的大小是正确的,357kb。
当我在Gmail中手动附加pdf
文档时,我可以看到内部的内容(不是空白页)。
手动附加文件时需要5秒钟。使用VBA代码,电子邮件会自动发送,这可能是我有空白页面的原因。 (我猜,Gmail没有足够的时间来处理文档)。
我很想使用Gmail或可能使用Windows Mail。
Dim Mail As New Message
Dim Config As Configuration
Set Config = Mail.Configuration
Config(cdoSendUsingMethod) = cdoSendUsingPort
Config(cdoSMTPServer) = "smtp.gmail.com"
Config(cdoSMTPServerPort) = 25
Config(cdoSMTPAuthenticate) = cdoBasic
Config(cdoSMTPUseSSL) = True
Config(cdoSendUserName) = "pchiknagi@gmail.com"
Config(cdoSendPassword) = "XXXXXXXX"
Config.Fields.update
Mail.To = "pchiknagi@gmail.com"
Mail.From = "pchiknagi@gmail.com"
Mail.Subject = "test"
Mail.AddAttachment "c:\temp\sample.pdf"
Mail.Send
答案 0 :(得分:0)
我将其用作配置:
'Enable SSL Authentication
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
'Make SMTP authentication Enabled=true (1)
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'Set the SMTP server and port Details
'Get these details from the Settings Page of your Gmail Account
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"smtp.gmail.com"
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Set your credentials of your Gmail Account
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = _
"mymail@gmail.com"
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = _
"xxxxx"
'Update the configuration fields
Mail.Configuration.Fields.Update