Skip to content

Commit

Permalink
Merge pull request googleapis#62 from blastter/master
Browse files Browse the repository at this point in the history
Sweet, I didn't know this was possible. Useful addition. Thanks.
  • Loading branch information
Narcolapser authored Oct 4, 2017
2 parents 23eff38 + b3b3a2e commit 1fddfae
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions O365/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Message(object):
getSenderName -- gets the name of the sender, if possible.
getSubject -- gets the email's subject line.
getBody -- gets contents of the body of the email.
setFrom -- sets the email's sender in case username have permissions to send mail for
other account.
addRecipient -- adds a person to the recipient list.
setRecipients -- sets the list of recipients.
setSubject -- sets the subject line.
Expand Down Expand Up @@ -95,6 +97,8 @@ def sendMessage(self):
data['Message']['Subject'] = self.json['Subject']
data['Message']['Body']['Content'] = self.json['Body']['Content']
data['Message']['Body']['ContentType'] = self.json['Body']['ContentType']
if 'From' in self.json:
data['Message']['From'] = self.json['From']
data['Message']['ToRecipients'] = self.json['ToRecipients']
data['Message']['CcRecipients'] = self.json['CcRecipients']
data['Message']['BccRecipients'] = self.json['BccRecipients']
Expand Down Expand Up @@ -217,6 +221,15 @@ def addRecipient(self, address, name=None, r_type="To"):
self.json[r_type + 'Recipients'].append(
{'EmailAddress': {'Address': address, 'Name': name}})

def setFrom(self, address, name = None):
'''
Set custom sender through an other account, in case you have permissions to send as
the other account.
'''
if name == None:
name = address[:address.index('@')]
self.json['From'] = {"EmailAddress":{"Address":address, "Name": name}}

def setSubject(self, val):
'''Sets the subect line of the email.'''
self.json['Subject'] = val
Expand Down

0 comments on commit 1fddfae

Please sign in to comment.