Venkatesh Kumar M
Venkatesh Kumar M

Reputation: 31

How can I reply to Outlook email using Python?

I am trying to reply to Outlook email as we do manually so it goes with previous conversations.

Below code is giving some error:

Failed to send to the recipient address.

import win32com.client, datetime
from datetime import timedelta    

outlook =win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") # to trigger outlook application
inbox = outlook.GetDefaultFolder(6) # 6 is used for the index of the folder
messages = inbox.Items  
message = messages.GetLast()# message is treated as each mail in for loop 
for message in messages:                                          
    if message.Subject=="request": # based on the subject replying to email
        #body_content = message.body  
        message.Reply()  
        message.Body = "shortly will be processed!!!"  
        message.Send()  

Upvotes: 1

Views: 10643

Answers (3)

Akhil
Akhil

Reputation: 1

Continuing on Oliver's answer

To reply all:

rplyall = message.ReplyAll()

To reflect previous conversations:

rplyall.Body = "your message here"+rplyall.Body()
rplyall.Send()

Upvotes: 0

KevinST
KevinST

Reputation: 31

Since MailItem.Body is a String and it is not callable. Reference document I think the correct code in @Akhil 's answer is

    rplyall.Body = "your message here" + rplyall.Body
    rplyall.Send()

Upvotes: 0

Oliver
Oliver

Reputation: 29453

The reply is a MailItem returned by reply(). So try this:

reply = message.Reply() 
reply.Body = "shortly will be processed!!!" 
reply.Send() 

Upvotes: 0

Related Questions