【问题标题】:Sendgrid Email Excel VBA SMTPSendgrid 电子邮件 Excel VBA SMTP
【发布时间】:2016-02-17 02:39:39
【问题描述】:

我正在尝试将 Sendgrid SMTP 与 excel 集成,以便直接从我的 excel 表中发送电子邮件。下面给出的代码返回错误消息“无法将消息发送到 SMTP 服务器”。 Error Image

Sub Manufactureremail1()
'sends email to manufacturer using Sendgrid
'Application.ScreenUpdating = False
 'While (True)
    Dim iMsg As Object
    Dim iConf As Object
    Dim strbody As String
    '    Dim Flds As Variant

    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")

        iConf.Load -1    ' CDO Source Defaults
        Set Flds = iConf.Fields
        With Flds
            .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
                           = "smtp.sendgrid.net"
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
            .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "myusername"
            .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypassword"
            .Update
        End With

    

    With iMsg
        Set .Configuration = iConf
        .To = Application.WorksheetFunction.VLookup(Selection.Cells(2, 1), Worksheets("Contacts").Range("email_data"), 2, False)
        .CC = ""
        '.BCC = Application.WorksheetFunction.VLookup(Selection.Cells(2, 3), Worksheets("Contacts").Range("email_data"), 2, False)
        .From = """Yash"" <yashagarwal080@gmail.com>"
        .Subject = "Order of " & Selection.Cells(2, 3)
        
        '.addattachment Worksheets("Contacts").Range("I6")
        '.addattachment Worksheets("Contacts").Range("I7")
        
        .htmlBody = "Message"
        .send
       'MsgBox "Emails Sent!", vbInformation, "Success"
    
    End With
 'DoEvents
 'Wend
'Application.ScreenUpdating = True
End Sub

【问题讨论】:

  • 试试.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
  • @Jeeped 已经试过了。没用!
  • 在工具中添加对 Microsoft CDO 的引用后,这对我也有用。您是否尝试过在 html 正文字符串中使用印度语?

标签: excel smtp email sendgrid vba


【解决方案1】:

通过添加将您的配置设置为使用 SSL:

.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1

【讨论】:

  • 这也不起作用。错误“传输无法连接到服务器”
【解决方案2】:

Yash,我在没有邮件服务器配置的情况下测试了你的代码,它对我来说只做了两件事。 1.我在工具->参考中引用了微软CDO。 2.我把端口地址改成25

【讨论】:

  • 这对我有用。知道如何在字符串变量中使用印度语言字体,用于电子邮件正文。
猜你喜欢
  • 1970-01-01
  • 2012-05-26
  • 1970-01-01
  • 1970-01-01
  • 2013-03-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-27
  • 2018-08-08
相关资源
最近更新 更多