Hello Tim, Thanks for your response. After sending the post I was able to do attachments but other properties like SenderEmailAddress are not working. It gives me an AttributeError as follows:
Traceback (most recent call last): File "autoMailer.py", line 146, in <module> AutoMailSend() File "autoMailer.py", line 27, in __init__ self.sendMail("Outlook") File "autoMailer.py", line 118, in sendMail mail.SenderEmailAddress = 'shashwat...@gmail.com' File "C:\Python272\lib\site-packages\win32com\client\__init__.py", line 470, i n __setattr__ raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr )) *AttributeError: '<win32com.gen_py.Microsoft Outlook 12.0 Object Library._MailIte m instance at 0x39818584>' object has no attribute 'SenderEmailAddress'* C:\Temp> I am confused as 'Attachments' works but not other properties. Could you provide some more hints? I was also trying to add signature by doing: mail.AddBusinessCard = 'Signature1' but that too gave an error. Thanks for your help. Sinha. On Thu, Jun 16, 2011 at 4:21 PM, Tim Roberts <t...@probo.com> wrote: > 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 >
_______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32