I have a function which sends an email via outlook when given text, a subject, and recipients shown below:
def __Emailer(text, subject, recipient, auto=True):
import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
if type(recipient) == type([]):
for name in recipient:
mail.Recipients.Add(name)
else:
mail.To = recipients
mail.Subject = subject
mail.HtmlBody = text
if auto:
mail.send
else:
mail.Display(True)
Now, I know that type comparisons in Python are strongly discouraged, but I can't think of a better way to do this. I want it to send to multiple addresses if recipient
is a list using the mail.Recipients.Add(name)
, and mail.To
if there is only one name (not given as a list). How can I accomplish this without using nasty type comparisons?