简体   繁体   中英

sending emails with smtplib in python from shared mailbox

I am working on script to send emails. Emails are supposed to be send from a shared mailbox in outlook. This shared mailbox doesn't have a password and here is the trick: on the one hand I need the authenticate and provide a password, on the other hand I have no password to provide. I ran the scripted with my professional outlook mailbox (email address + password) and it works.

Here is my config:

MY_ADDRESS = "---emailaddressofthesender---"
PASSWORD = ""
MESSAGE = "some message"

# set up the SMTP server
s = smtplib.SMTP(host='smtp-mail.outlook.com', port=587)

s.starttls()
s.login(MY_ADDRESS, PASSWORD)

msg = MIMEMultipart()       # create a message

# setup the parameters of the message
msg['From']=MY_ADDRESS
msg['To']="---emailaddresseofthereceiver---"
msg['Subject']="This is TEST"

# add in the message body
msg.attach(MIMEText(MESSAGE, 'plain'))

# send the message via the server set up earlier.
s.send_message(msg)
del msg

# Terminate the SMTP session and close the connection
s.quit()

I tried:

  • Read the doc smtplib. Unless mistaken, I found no mentions about authentications without password.
  • PASSWORD = "": authentication error
  • PASSWORD = None: authentication error
  • s.login(MY_ADDRESS): PASSWORD argument is missing
  • remove s.login() method from the script: Client was not authenticated to send anonymous mail during MAIL FROM [PR0P264CA0184.FRAP264.PROD.OUTLOOK.COM]

The only working solution I have now is to send from my mailbox credentials and not from the shared mailbox. For the sake of this project, this solution is not acceptable.

Many thanks in advance for your help

在 s.send() 步骤之前添加它,它将起作用。

s.SentOnBehalfOfName = 'SharedFolder'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM