Sending email with Workmail via Python

0

I'm trying to send email via Workmail using Python

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase

def send_email(email_recipient, email_subject, email_message):
    try:
      server = smtplib.SMTP_SSL('smtp.mail.eu-west-1.awsapps.com', 465)
      server.ehlo()
      server.login('username', 'password')
      text = msg.as_string()
      server.sendmail(email_sender, email_recipient, text)
      print('Email sent to %s' % email_recipient)
    except Exception as e:
      print(e)
      print("SMTP server connection error")
    return True

def main():
  send_email('email@domain.com', 'hello', 'world')

main()

This does not work because

(535, b'Authentication credentials invalid')
SMTP server connection error

But using username and password, I am able to log into https://webmail.mail.eu-west-1.awsapps.com/workmail/ with these credentials.

So my questions are

  1. Is it possible to send an email using the SMTP server of Workmail.
  2. If yes, why are those credentials invalid (I also tried base64)

Many thanks in advance!

  • Hi,

    The username field must be the full email address of the user. This is different from webmail where a username suffices. Hope this helps.

  • Hi @JohnAWS,thanks for your comment ! That does actually solved the issue, I had to send a test email from Workmail to get the email address used! Many thanks! :)

질문됨 2년 전1020회 조회
1개 답변
1

As mentioned by John (of AWS) above, use full email address for SMTP.

However please note that Workmail shouldnt be use for bulk emails and its primary use case would be Employees of a given company need to email each other on their company email addresses (and to some extent their individual partners).

Check also SES service incase its a better fit.

답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠