I have been using the following code to send emails from excel to a nominated person. It works fine if I go into my gmail and turn on "Use Less Secure Devices". Google intend to discontinue this option. How can I modify my code to overcome this hurdle. Any advice would be extremely welcome.
Sub MyGmailMacro()
Dim iMsg As Object
Dim iConf As Object
Dim Flds As Variant
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1
Set Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "myemail"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypassword"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" 'smtp mail server
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 'stmp server
.Update
End With
With iMsg
Set .Configuration = iConf
.To = MyReceiver
.From = "myemail"
.Subject = MySubject
.TextBody = MyMessage
.AddAttachment "C:\Attach1.doc"
.AddAttachment "C:\Attach2.doc"
.Send
End With
Set iMsg = Nothing
Set iConf = Nothing
End Sub