2

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?

Community
  • 1
  • 1
izdi
  • 555
  • 1
  • 7
  • 24

1 Answers1

1

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 = "abc@xyz.com" # 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   = ['abc@xyz.com'] # 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)
VIKASH JAISWAL
  • 828
  • 1
  • 5
  • 11
  • Thanks for response. Are there any preferences for IMAP/POP servers? – izdi Dec 10 '13 at 13:05
  • Since I have never used something like that so don't know about it but I see there are other libraries that have. For instance look at this link: http://stackoverflow.com/questions/18156485/receve-replys-from-gmail-with-smtplib-python – VIKASH JAISWAL Dec 11 '13 at 06:07