0

I am trying to send e-mails to a list of contacts, along with a blind copy (BCC) to myself, using Yagmail and Python. I couldn't find any examples in the Yagmail documentation that described how to do this. I know it's possible, but I keep getting an error with my current code.

Can anyone help me resolve this?

Note: This code works until I add "bcc" as a method-parameter.

The Code:

yag = yagmail.SMTP(
            user={real_sender:alias_sender}, password="xxxxxx", host='smtp.xxxxxx.com', port='587',
            smtp_starttls=True, smtp_ssl=None, smtp_set_debuglevel=0, smtp_skip_login=False,
            encoding='utf-8', oauth2_file=None, soft_email_validation=True)

to = all_receivers ### list of contacts 1
bcc = all_receivers_bcc ### list of contacts 2
subject = 'SUBJECT HERE'
contents = 'HTML CONTENT HERE'

yag.send(to, bcc, subject, contents) ### FAILS HERE WHEN THE "bcc" is added
Matthew E. Miller
  • 557
  • 1
  • 5
  • 13
Julio S.
  • 944
  • 1
  • 12
  • 26

2 Answers2

1

You need to tell python which parameter you are inputting. If you don't, you need to make sure parameters are sent in the right order. Try this:

yag.send(to=all_receivers, bcc=all_receivers_bcc , subject='SUBJECT HERE', contents='HTML CONTENT HERE')
RegularNormalDayGuy
  • 685
  • 1
  • 8
  • 25
1

I think this code will work, please test:
Yagmail Usage Doc
This example uses string interpolation to place the variables.

yag = yagmail.SMTP(
            user={real_sender:alias_sender}, password="xxxxxx", host='smtp.xxxxxx.com', port='587',
            smtp_starttls=True, smtp_ssl=None, smtp_set_debuglevel=0, smtp_skip_login=False,
            encoding='utf-8', oauth2_file=None, soft_email_validation=True)

all_receivers = str(['aContact1@gmail.com','aContact2@gmail.com','aContact3@gmail.com']) #contacts list
all_receivers_bcc = str(['bbcContact1@gmail.com','bbcContact2@gmail.com','bbcContact3@gmail.com'])#contact list
subject = 'SUBJECT HERE'
contents = 'HTML CONTENT HERE'

yag.send(to='{all_receivers}', subject='{subjects}', contents='{contents}', bcc='{all_receivers_bbc}')
Matthew E. Miller
  • 557
  • 1
  • 5
  • 13