xreef / EMailSender

Arduino, esp32, Esp8266 EMailSender with Arduino IDE, simple library to send email via smtp with attachments.
https://www.mischianti.org/category/my-libraries/emailsender-send-email-with-attachments/
MIT License
74 stars 26 forks source link

Send email to provider other than GMail, ie Office365/Outlook #14

Closed d-rankin closed 3 years ago

d-rankin commented 3 years ago

As per the previous post, I am getting a similar error message when trying to use Office365 accounts (example@outlook.com, smtp.office365.com, port 587). I believe the equivalent to Less Secure Apps with Office365 is to use an App Password instead but I've not had any luck getting this to work. Are you able to verify this works with an Office365 account by any chance? Thanks.

Office365 settings:

Server name: smtp.office365.com Port: 587 Encryption method: STARTTLS

code:

const char email_login = "example@outlook.com"; const char email_password = "App Password"; const char email_from = "example@outlook.com"; const char name_from = "MoistureSensor"; const char smtp_server = "smtp.office365.com"; // const int smtp_port = 587;

EMailSender emailSend(smtp_server, email_password, email_from, name_from, 587);

Error:

00:28:41.508 -> .......................... 00:28:47.274 -> Connection: ESTABLISHED 00:28:47.274 -> Got IP address: 192.168.0.117 00:29:07.887 -> Sending status: 00:29:07.887 -> 0 00:29:07.887 -> 2 00:29:07.887 -> Could not connect to mail server

xreef commented 3 years ago

Hi d-rankin, I'm doing some fix on esp32, the error you have It's similar to the fixed one. Please retry. Bye Renzo

d-rankin commented 3 years ago

Hey Renzo,

Thanks for the reply. Unfortunately this is still happening with the same 'Could not connect to mail server' with the 2.4.2 update. I am using ESP8266 in case that makes any difference here, many thanks

xreef commented 3 years ago

Hi d-rankin, I try to check and the problem is that my library not support STARTTSL only SSL. If I find a quite bit of time I'm going to implement It. Bye Renzo

Andy2051 commented 2 years ago

I am getting exactly the same, also running on an esp8266 (nodemcu):

Connection: ESTABLISHED
Got IP address: 192.168.0.113
Sending status: 
status=0
code=2
description=Could not connect to mail server

Email settings (as stated by my service provider):

Non-SSL Settings (NOT Recommended)
Username:   myemail@mydomain.org.uk
Password:   Use the email account’s password.
Incoming Server:    mail.mydomain.org.uk
IMAP Port: 143 POP3 Port: 110
Outgoing Server:    mail.mydomain.org.uk
SMTP Port: 587

Relevant code in the script

EMailSender emailSend("myemail@mydomain.org.uk", "mypassword", "myemail@mydomain.org.uk", "myemail@mydomain.org.uk", "mail.mydomain.org.uk",587);`

I have spent nearly a day going round in circles on this.

EDIT - interesting, tried changing to Secure SSL/TLS Settings (Recommended), port = 465 and got this:

Connection: ESTABLISHED
Got IP address: 192.168.0.113
sending email to andy
Sending status: 
status=0
code=250
description=Identification error (220-We do not authorize the use of this system to transport unsolicited, 
)
was the message sent

I have got it working with a gmail account but, google will be turning off "less secure apps":

To help keep your account secure, starting May 30, 2022, ​​Google will no longer support the use of third-party apps or devices which ask you to sign in to your Google Account using only your username and password.

xreef commented 2 years ago

Hi Andy, the port SMTP Port: 587 say that the service is in STARTTLS, and It isn't supported. Sorry Renzo

Andy2051 commented 2 years ago

Cross posted, have it working with gmail, but see my edit.

Andy2051 commented 2 years ago

Sorted! Set up a gmail account for my oil tank sensor and set an app password. Not really what I wanted as I try and avoid anything google, but it works.

Thanks for your efforts, I will now be able to email the tank reading daily, or if contents drop suddenly, send a warning email (given what is happening at the moment, central heating oil has doubled in price in the last two weeks = expect more theft :( ).

xreef commented 2 years ago

Hehehehe.. I add a set of camera with a 3Km wifi antenna to prevent that. Also yahoo have SSL email.

Would you like to share your project?

Andy2051 commented 2 years ago

Still in progress!

Still doing the software, hardware will be battery powered (18650) with a solar panel for recharge. I'll probably have to put up an external POE access point. Started this when my current sensor failed and the supplier wants £250 for their latest model and they want a monthly subscription on top - no thank you!

My main problem is I'm not a fan of C++ and not fluent in it, normally use pascal, but not available for the Arduino. https://forums.linuxmint.com/viewtopic.php?p=2130761#p2130761 7,500 lines of code using the lazarus IDE.

xreef commented 2 years ago

Hi @Andy2051, It's very interesting, If you need some help you can write also on the site forum, and I try to support your project.

I develop a lot in the past with pascal, but now I think you must migrate to another language, the resource becomes limited.

I found it very simple to use (for the people that came from Delphi or VB) Java with https://www.eclipse.org/windowbuilder/ to create desktop applications. Or NodeJS to create a web application (FE and BE).

Bye Renzo