Shashwat Sinha wrote:
> Hi,
>  
> I wrote this simple code that works fine:
>  
> import win32com.client as W
>  
> olook = W.gencache.EnsureDispatch("%s.Application" %profilename)
> mail = olook.CreateItem(W.constants.olMailItem)
> mail.Recipients.Add('x...@yahoo.com <mailto:%2...@yahoo.com>)
> mail.Subject = 'Hello'
> mail.Body = 'Hello'
> mail.Send()
>
> When I have Outlook open it sends the email from my Outlook account. 
> How can I change the "From" field in the code so that I can specify a
> different sender?  Also how can I add attachment from this python code?

Search for the Outlook object model.  Your "mail" object is a MailItem
object.  That object has many properties, including SenderEmailAddress,
SenderEmailType, and SenderName.

It also has an Attachments property, which is a collection.  You should
be able to do something like this:

    mail.Attachments.Add( filename, win32com.constants.olByValue )

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to