【问题标题】:Send pdf document using Gmail with VBA使用带有 VBA 的 Gmail 发送 pdf 文档
【发布时间】:2018-08-04 12:37:04
【问题描述】:

我正在尝试使用 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

【问题讨论】:

  • 您在哪个应用程序中运行此代码?看起来像前景
  • 我使用 Excel VBA
  • 值得添加excel标签
  • 刚刚添加了 excel 作为标签。我不得不说,我到处寻找,但找不到任何解决方案。它可能适用于 Outlook,但我没有应用程序
  • 好吧,你必须检查 Outlook 库,所以实际上 Outlook 标记可能是合适的。

标签: excel vba email pdf gmail


【解决方案1】:

我用这个作为配置:

   '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

【讨论】:

    猜你喜欢
    • 2018-11-11
    • 2015-10-21
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多