Error using sendmail (line 175)

I've tried almost everything that's already on here but I keep getting the same error. I've allowed less secure apps on my gmail and allowed POP and IMAP. Even using outlook does not work. Turning off my firewall seems to have no effect
For reference I'm using: https://www.mathworks.com/matlabcentral/fileexchange/20227-send-email-to-gmail-account. I have eddited the details so that they are correct for my account. I've tried changing the port to 587 and used other solutions on MATLAB Answers.
It is always:
Error using sendmail (line 175)
Could not connect to SMTP host: smtp.gmail.com, port: 587; (Or 465 when I try that port)
Connection refused: connect
I understand that a few people have had similar problems but none of the solutions work for me.
Many Thanks

Respuestas (1)

Cris LaPierre
Cris LaPierre el 1 de Abr. de 2019
Editada: per isakson el 2 de Abr. de 2019

0 votos

I've had success using the instructions provided here. No file exchange needed.
You do have to allow less secure apps access to your google account, but it sounds like maybe you've already done that?
This post contains some of these details as well with links.

10 comentarios

Devon Dayah
Devon Dayah el 2 de Abr. de 2019
Editada: Devon Dayah el 2 de Abr. de 2019
I've also tried those ones but with no luck, they come up with the same error. Yes I have enabled less secure apps on my account but wether or not I do doesn't seem to change anything.
Actually, I've noticed that Matlab seems to be 'skipping' some lines of code. When I step through it runs as intended but if I do not then it seems to pass it e.g I have a list box in a GUI that is ment to update when a textbox is interacted with but won't unless I step through the code, which is annoying but for another time. I can't really explain it very well because I don't know what is happening. Do you think this is the cause? When I next get the chance, I'll step through this code and see if if changes anything.
Update: I have tried stepping through the code and it has not effected the outcome. I'm sorry for wasting your time with it.
Cris LaPierre
Cris LaPierre el 2 de Abr. de 2019
Do you use 2-step verification on your google account?
Devon Dayah
Devon Dayah el 3 de Abr. de 2019
Editada: Devon Dayah el 3 de Abr. de 2019
No, I don't. Do you think I should?
Update: Now it is saying port 25 even though I've set it to 587/465. I haven changed anything, just closed my laptop and opened it again. When I check what 'props' is it says the port is 587/465 but when the error from sendmail appears it says port 25.
It seems that the port now only changes using:
props.setProperty( 'mail.smtp.port', '587' );
when yesterday it was fine with:
props.setProperty('mail.smtp.socketFactory.port','465');
Cris LaPierre
Cris LaPierre el 3 de Abr. de 2019
No. I was wondering if that might be the problem since that might have been a reason why sendmail wasn't working.
Devon Dayah
Devon Dayah el 4 de Abr. de 2019
Editada: Devon Dayah el 4 de Abr. de 2019
I've just asked a friend of mine to try. For the exact same code he gets:
Error using sendmail (line 175)
Authentication failed (using port 465)
Exeption reading responce
Unrecognised SSL message, plaintext connection? (for port 587)
For the same email adress and using ('mail.smtp.socketFactory.port','465');
Cris LaPierre
Cris LaPierre el 4 de Abr. de 2019
Share your code. Otherwise we can't move beyond this point. Be sure to remove any of your account details first.
Devon Dayah
Devon Dayah el 4 de Abr. de 2019
Editada: Devon Dayah el 4 de Abr. de 2019
function send_mail_message(id,subject,message,attachment)
clc;
subject = 'testing';
message = '1 2 3';
attachment = '';
mail = 'this@gmail.com'; %Redacted
password = 'not here'; %Redacted
if nargin == 1
message = subject;
subject = '';
elseif nargin == 2
message = '';
attachment = '';
elseif nargin == 3
attachment = '';
end
id= 'mine'; %Redacted
emailto = strcat(id,'@gmail.com');
setpref('Internet','E_mail',mail);
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','SMTP_Username',mail);
setpref('Internet','SMTP_Password',password);
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth','true');
props.setProperty('mail.smtp.socketFactory.class', 'javax.net.ssl.SSLSocketFactory');
props.setProperty('mail.smtp.socketFactory.port','465');
%props.setProperty( 'mail.smtp.port', '587' );
if strcmp(mail,'GmailId@gmail.com')
disp('Please provide your own gmail.')
disp('You can do that by modifying the first two lines of the code')
disp('after the comments.')
end
sendmail(emailto,subject,message,attachment)
end
Cris LaPierre
Cris LaPierre el 4 de Abr. de 2019
Sorry to report your code works for me. It does mean there's nothing wrong with the code, though.
At this point, I'd just be guessing why you are getting the error. Perhaps try reaching out to your ISP or google to see if they can see why your requests are not going through?
Devon Dayah
Devon Dayah el 5 de Abr. de 2019
Editada: Devon Dayah el 5 de Abr. de 2019
It's probably my IPS as a friend of mine seems to be doing better. We are using the same email address. I'll have to check if it works when connected to my work Wi-Fi as that is where it'll be run. Thanks for your help anyway, it's less worrying if I know the code works.
Devon Dayah
Devon Dayah el 8 de Mayo de 2019
I understand it’s been a while but apparently I need to define certificates before I use sendmail.

Iniciar sesión para comentar.

Productos

Versión

R2018b

Preguntada:

el 31 de Mzo. de 2019

Comentada:

el 8 de Mayo de 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by