Reputation: 575
In addition to this thread send outlook mail via win32com, i'd like to know if there is a possibility to use mail.From
alike method. When you create an email, you can choose from what email you'd like to send it.
And for the future, where could i get this information from? I mean do those commands work with COM object of outlook application?
Upvotes: 2
Views: 2169
Reputation: 838
Here's a code which I have been using for long time and hopefully will work for you as well,
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.Utils import COMMASPACE, formatdate
from email import Encoders
def sendMail(to, subject, text):
assert type(to)==list
fro = "[email protected]" # use your from email here
msg = MIMEMultipart()
msg['From'] = fro
msg['To'] = COMMASPACE.join(to)
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = subject
msg.attach(MIMEText(html, 'html'))
smtp = smtplib.SMTP('mailhost.abcd.co.in') #use your mailhost here, it's dummy.
smtp.sendmail("", to, msg.as_string() )
smtp.close()
TOADDR = ['[email protected]'] # list of emails address to be sent to
html = """\
<html>
<head></head>
<body>
<p>Hi!<br>
How are you?<br>
Here is the <a href="http://www.python.org">link</a> you wanted.
</p>
</body>
</html>
"""
sendMail( TOADDR, "hello",html)
Upvotes: 1