2

I am trying to add cc in Gmail python API. So far I haven't seen any example on google. Here is what I tried in create_message method:

def create_message(sender, to, subject, message_text, cc=None):
  message = MIMEText(message_text,'html')
  message['to'] = to
  if cc:
    message['cc'] = cc
  message['from'] = sender
  message['subject'] = subject
  return {'raw': base64.urlsafe_b64encode(message.as_string())}

I looked through MIMEText.py and discovery.py but couldn't find anything. Thanks!

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
nomem
  • 1,568
  • 4
  • 17
  • 33
  • 1
    Are you actually using the gmail API, or just using the stdlib to talk to gmail's server? `MIMEText` doesn't care what headers you stick on a message; that's up to the code that _uses_ the message, so we need to see that part of your code. – abarnert Apr 06 '18 at 22:08
  • Please check https://stackoverflow.com/questions/1546367/python-how-to-send-mail-with-to-cc-and-bcc?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Afsan Abdulali Gujarati Apr 07 '18 at 00:00
  • @abarnert I am using gmail API and (example code from the tutorial)[https://developers.google.com/gmail/api/guides/sending]. – nomem Apr 07 '18 at 00:42
  • 1
    @AfsanAbdulaliGujarati this code seems to be for standard smtp API. – nomem Apr 07 '18 at 00:43
  • please consider your tagging it will help you get the correct answer. – Linda Lawton - DaImTo Apr 07 '18 at 10:30

1 Answers1

1

Have you tried message['cc'] = "cc.1@gmail.com,cc.2@gmail.com,cc.3@gmail.com"? This is how I solved mine.