2015-11-16 1 views
0

J'essaie d'intégrer Sendgrid SMTP avec Excel pour envoyer des emails directement à partir de ma feuille Excel. Le code indiqué ci-dessous renvoie une erreur indiquant "Impossible d'envoyer le message au serveur SMTP". Error ImageSendgrid Email Excel VBA SMTP

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"" <[email protected]>" 
 
     .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

+0

Essayez avec '.Item (" http://schemas.microsoft.com/cdo/configuration/smtpserverport ") = 465' – Jeeped

+0

@Jeeped J'ai déjà essayé. N'a pas fonctionné! – Yash

Répondre