This is my code so far for gmail (any missing email/password assume I will enter correct one just removed for privacy reasons) Ultimately the hope is to send via my Outlook email, but right now I just want to prove it works via gmail, as gmail is my personal accounts and outlook would be for work... Would rather not send random outlook messages until I have coding 100% down.
When I try to send now, it just gives an error message (transport failed to connect to server)
Can someone help? If we get this resolved I will probably back to get help with outlook, but lets focus on this for now!
You guys are awesome!! Thanks!!
When I try to send now, it just gives an error message (transport failed to connect to server)
VBA Code:
Sub Send_Email_QSS()
Dim CDO_Mail As Object
Dim CDO_Config As Object
Dim SMTP_Config As Variant
Dim strSubject As String
Dim strFrom As String
Dim strTo As String
Dim strCc As String
Dim strBcc As String
Dim strBody As String
strSubject = Sheets("Emails").Range("A2").Value 'trying to use cell value to fill in missing items'
strFrom = "MyEmail" 'this would end up being the same from email everytime'
strTo = "Email Being Sent To" 'ultimately the hope is to set this to cell value as well, vs the same email address everytime'
strCc = ""
strBcc = ""
strBody = Sheets("Emails").Range("B2").Value
Set CDO_Mail = CreateObject("CDO.Message")
On Error GoTo Error_Handling
Set CDO_Config = CreateObject("CDO.Configuration")
CDO_Config.Load -1
Set SMTP_Config = CDO_Config.Fields
With SMTP_Config
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "MyEmail@gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "MyPassword"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587 'found this by going into my email settings'
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Update
End With
With CDO_Mail
Set .Configuration = CDO_Config
End With
CDO_Mail.Subject = strSubject
CDO_Mail.From = strFrom
CDO_Mail.To = strTo
CDO_Mail.TextBody = strBody
CDO_Mail.CC = strCc
CDO_Mail.BCC = strBcc
CDO_Mail.Send
Error_Handling:
If Err.Description <> "" Then MsgBox Err.Description
End Sub
Can someone help? If we get this resolved I will probably back to get help with outlook, but lets focus on this for now!
You guys are awesome!! Thanks!!