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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,224,828
Messages
6,181,201
Members
453,022
Latest member
RobertV1609

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