srikanthg2310
New Member
- Joined
- Nov 9, 2015
- Messages
- 17
Hi,
I am using the below macro to send email from my gmail to another email address (with attachment). However, I am getting an error when I run the code.
Can someone please fix the issue?
Sub CommandButton1_Click()
Dim Mail As New message
Dim x As Integer
x = 1
Do While Sheet1.Cells(x, 1) <> ""
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) = "xxxxxxxxxx@gmail.com"
Config(cdoSendPassword) = "xxxxxxxx"
Config.Fields.Update
Mail.To = Sheet1.Cells(x, 1)
Mail.From = Config(cdoSendUserName)
Mail.Subject = Sheet1.Range("B2").Value
Mail.TextBody = Sheet1.Range("B1").Value
Mail.AddAttachment (Sheet1.Range("B4").Value)
x = x + 1
Mail.Send
Loop
MsgBox "Sent"
End Sub
I am using the below macro to send email from my gmail to another email address (with attachment). However, I am getting an error when I run the code.
Can someone please fix the issue?
Sub CommandButton1_Click()
Dim Mail As New message
Dim x As Integer
x = 1
Do While Sheet1.Cells(x, 1) <> ""
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) = "xxxxxxxxxx@gmail.com"
Config(cdoSendPassword) = "xxxxxxxx"
Config.Fields.Update
Mail.To = Sheet1.Cells(x, 1)
Mail.From = Config(cdoSendUserName)
Mail.Subject = Sheet1.Range("B2").Value
Mail.TextBody = Sheet1.Range("B1").Value
Mail.AddAttachment (Sheet1.Range("B4").Value)
x = x + 1
Mail.Send
Loop
MsgBox "Sent"
End Sub