-1

Im using python 2.7 Im trying to send emails to more than one person. Only one person receives not others.

My code is;

import smtplib
import time
from email.header import Header
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from utilities.ConfigReader import *


def sendEmailNotification(subject, body):
    sender, receiver = getNotificationSettings()
    smtpServer, smtpPort, timeout = getSMTPSettings()
    msg = MIMEMultipart()
    R = receiver.split(",")
    body = MIMEText(body, 'plain', 'utf-8')
    msg['Subject'] = Header(subject, 'utf-8')
    msg['From'] = sender
    msg['To'] = receiver
    msg.attach(body)

    server = smtplib.SMTP(smtpServer, smtpPort)
    server.ehlo()
    try:
        print receiver
        print R
        server.sendmail(sender, R, msg.as_string())
    except smtplib.SMTPException:
        time.sleep(float(timeout))
        server.sendmail(sender, R, msg.as_string())
    server.quit()

sendEmailNotification("Test","Test")

Here R prints;

['test@lob.com', 'ratha@lob.com']

receiver prints;

test@lob.com, ratha@lob.com

I followed following thread but didnt work to me;

How to send email to multiple recipients using python smtplib?

What im doing wrong here?

SuperKogito
  • 2,998
  • 3
  • 16
  • 37
Ratha
  • 9,434
  • 17
  • 85
  • 163

1 Answers1

1

I figured out my issue. ratha@lob.com is in the list email test@lob.com . So I haven't received the email for ratha@lob.com , but received for test@lob.com . After changing two private emails, i receive in both emails. So code is working as expected.

Ratha
  • 9,434
  • 17
  • 85
  • 163