How to send emails using QTP from Microsoft Outlook
In the previous article, we saw how to send emails from QTP via Gmail & Yahoo Mail. There we wrote the code that connects to GMail/Yahoo SMTP Server and sends mails to any email id. But if you have MS Outlook installed in your machine, you can directly use Outlook to send emails to the required mail ids. Also, the code to send mails from Outlook is relatively simpler than code for sending mails from Gmail/Yahoo using Microsoft CDO technology. Let’s see how the code works –
Function fnSendEmailFromOutlook 'Create an object of type Outlook Set objOutlook = CreateObject("Outlook.Application") Set myMail = objOutlook.CreateItem(0) 'Set the email properties myMail.To = "some_mail_id@gmail.com" myMail.CC = "some_mail_id_2@gmail.com; some_other_mail@yahoo.com" 'Sending mails to multiple ids myMail.BCC = "" 'If BCC is not required, then this line can be omitted myMail.Subject = "Sending mail from MS Outlook using QTP" myMail.Body= "Test Mail Contents" myMail.Attachments.Add("D:\Attachment.txt") 'Path of the file to be attached 'Send the mail myMail.Send Wait(3) 'Clear object reference Set myMail = Nothing Set objOutlook = Nothing End Function
Please let us know if the above code works for you. Please use the comments section or contacts form to get in contact with us regarding any issues/suggestions. Happy Reading.. :–)
If you liked this article, you can join our blog to get new posts delivered directly in your inbox.
Pingback: How to send emails using QTP from Gmail and Yahoo - Automation Repository - Automation Repository()
Pingback: Part 5: Automating Outlook using QTP | Emails in Outlook - Automation Repository - Automation Repository()