Thank you for the detailed reply Kevin.
After a good night’s rest, I read your message, tested your suggestions without any luck and then dug a little deeper.
I am using a personal gmail account and I had set it up with 2-step verification. However, it is possible to “Allow less secure apps”, which google tries hard to dissuade people from doing - but they allow it. I created a new gmail account today, set “Allow less secure apps” to “ON”, copied a python script to send an email from the Digital Ocean Ubuntu server. The same one where Ghost is installed.
I received the email using the script on the same server. So the issue isn’t Digital Ocean nor Gmail.
I tried the new credentials in the config.production.json
file, same issue. However, I am not sure if I am configuring it correctly.
},
"mail": {
"from": "email@gmail.com",
"transport": "SMTP",
"options": {
"service": "Gmail",
"host": "smtp.gmail.com",
"port": 465,
"secure": true,
"auth": {
"user": "email@gmail.com",
"password": "password"
}
}
},
This is the script I used
import smtplib, ssl
class Mail:
def __init__(self):
self.port = 465
self.smtp_server_domain_name = "smtp.gmail.com"
self.sender_mail = "GMAIL_ADDRESS"
self.password = "SECURE_PASSWORD"
def send(self, emails, subject, content):
ssl_context = ssl.create_default_context()
service = smtplib.SMTP_SSL(self.smtp_server_domain_name, self.port, context=ssl_context)
service.login(self.sender_mail, self.password)
for email in emails:
result = service.sendmail(self.sender_mail, email, f"Subject: {subject}\n{content}")
service.quit()
if __name__ == '__main__':
mails = input("Enter emails: ").split()
subject = input("Enter subject: ")
content = input("Enter content: ")
mail = Mail()
mail.send(mails, subject, content)
Sources: