Mailing from within VBA code fails

TPFKAS

Board Regular
Joined
Mar 1, 2010
Messages
62
I am using this code for mailing a file using gmail:


Code:
       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") = Mailfrom
        .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = MailPW
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = MailSMTP
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Update
    End With
DoEvents
    With iMsg
        Set .Configuration = iConf
        .To = Mailto
        .CC = ""
        .BCC = ""
        .From = Mailfrom
        .Subject = MailSubject
        .textbody = ""
        .AddAttachment FileName
        .send
    End With

This code works flawless at home connected to my home network. But on the road when connecting my laptop to my phone using as a hotspot it does not. I tried changing the SMTP server port to 465 but that does not help.
Any ideas what can cause this problem?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I already found the problem. It wasn't a VBA issue but a security setting in the Gmail account not allowing unknown apps to send mails. I can't quite figure out why is does work over my home network, but it does not when going over the 5G network.
 
Upvote 0
.
Which security setting required changing and how was it changed ? This will help others in the future.

Thanks.
 
Upvote 0

Forum statistics

Threads
1,223,701
Messages
6,173,920
Members
452,539
Latest member
deeme

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top