I need to create a VBA code that when it runs it sends an email (say "hello" and attach a picture located on my files) from my work email (let's say "tomhagen@pepsi.com"). I already have a code that can make this but with my personal email that uses normal @gmail.com (see below). When I change the UserName to my work email (tomhagen@pepsi.com) I get an "Error transport code 0x80040217". At the beginning I thought it was due to the password, but when I talk to my IT support from the office, they told me that the gmail does not have any password but it is accessed with the domain from Pepsi. My office uses gmail suit I attach the code below.
So far I found this that is related, VBA and GMail through a corporate login portal
Option Explicit
Private Sub Prepare_Notification_Email_Click()
Dim mail As New Message
Dim config As Configuration
Set config = mail.Configuration
config(cdoSendUsingMethod) = cdoSendUsingPort
config(cdoSMTPServer) = "smtp.gmail.com"
config(cdoSMTPServerPort) = 465
config(cdoSMTPAuthenticate) = cdoBasic
config(cdoSMTPUseSSL) = True
config(cdoSendUserName) = "tomhagen@gmail.com"
config(cdoSendPassword) = "password123"
config.Fields.Update
mail.To = "mailbox@gmail.com"
mail.From = config(cdoSendUserName)
mail.Subject = "Email Subject"
mail.HTMLBody = "<b>Email Body</b>"
mail.AddAttachment "C:\Users\thagen\Pictures\fitzroy.jpg"
On Error Resume Next
mail.Send
If Err.Number <> 0 Then
MsgBox Err.Description, vbCritical, "there was an error"
Exit Sub
End If
MsgBox "Email sent", vbInformation, "Sent"
End Sub
User contributions licensed under CC BY-SA 3.0