@@ -25,6 +25,8 @@ class Message(object):
25
25
getSenderName -- gets the name of the sender, if possible.
26
26
getSubject -- gets the email's subject line.
27
27
getBody -- gets contents of the body of the email.
28
+ setFrom -- sets the email's sender in case username have permissions to send mail for
29
+ other account.
28
30
addRecipient -- adds a person to the recipient list.
29
31
setRecipients -- sets the list of recipients.
30
32
setSubject -- sets the subject line.
@@ -95,6 +97,8 @@ def sendMessage(self):
95
97
data ['Message' ]['Subject' ] = self .json ['Subject' ]
96
98
data ['Message' ]['Body' ]['Content' ] = self .json ['Body' ]['Content' ]
97
99
data ['Message' ]['Body' ]['ContentType' ] = self .json ['Body' ]['ContentType' ]
100
+ if 'From' in self .json :
101
+ data ['Message' ]['From' ] = self .json ['From' ]
98
102
data ['Message' ]['ToRecipients' ] = self .json ['ToRecipients' ]
99
103
data ['Message' ]['CcRecipients' ] = self .json ['CcRecipients' ]
100
104
data ['Message' ]['BccRecipients' ] = self .json ['BccRecipients' ]
@@ -217,6 +221,15 @@ def addRecipient(self, address, name=None, r_type="To"):
217
221
self .json [r_type + 'Recipients' ].append (
218
222
{'EmailAddress' : {'Address' : address , 'Name' : name }})
219
223
224
+ def setFrom (self , address , name = None ):
225
+ '''
226
+ Set custom sender through an other account, in case you have permissions to send as
227
+ the other account.
228
+ '''
229
+ if name == None :
230
+ name = address [:address .index ('@' )]
231
+ self .json ['From' ] = {"EmailAddress" :{"Address" :address , "Name" : name }}
232
+
220
233
def setSubject (self , val ):
221
234
'''Sets the subect line of the email.'''
222
235
self .json ['Subject' ] = val
0 commit comments