salvato
Posts: 135
Joined: Tue Jan 15, 2013 9:21 pm

[Solved] How to send programmatically an email trough gmail ?

Fri Dec 01, 2023 4:22 pm

Hi all.
I would like to send an automated email from my Gmail account to the same Gmail account upon the receipt of an alarm.
I tried using

Code: Select all

$ echo -e "\nSending regards from Terminal." | msmtp -a gmail [email protected]


but the answer from the SMTP server of Gmail has been:

Code: Select all

Username and Password not accepted. Learn more at
https://support.google.com/mail/?p=BadCredentials

I visited the link but was unable to find how to proceed.

the

Code: Select all

.msmtprc
configuration file look as :

Code: Select all

# Default settings
defaults
auth    on
tls    on
tls_trust_file    /etc/ssl/certs/ca-certificates.crt
logfile ~/.msmtp.log
#GMail
account    gmail
host       smtp.gmail.com
port       587
from       [email protected]
user       [email protected]
password   mypassword

account default : gmail
Is there someone that can guide me ?

Thanks
Last edited by salvato on Sat Dec 02, 2023 3:00 pm, edited 1 time in total.

User avatar
DougieLawson
Posts: 42848
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: How to send programmatically an email trough gmail ?

Fri Dec 01, 2023 4:32 pm

You'll need to setup a Google application password.
https://support.google.com/accounts/answer/185833?hl=en
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

salvato
Posts: 135
Joined: Tue Jan 15, 2013 9:21 pm

Re: How to send programmatically an email trough gmail ?

Sat Dec 02, 2023 2:34 pm

Thank you.
Worked like a charm !

Return to “Other programming languages”