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 -
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| Function fnSendEmailFromOutlook'Create an object of type OutlookSet objOutlook = CreateObject("Outlook.Application")Set myMail = objOutlook.CreateItem(0)'Set the email propertiesmyMail.To = "some_mail_id@gmail.com"myMail.CC = "some_mail_id_2@gmail.com; some_other_mail@yahoo.com" 'Sending mails to multiple idsmyMail.BCC = "" 'If BCC is not required, then this line can be omittedmyMail.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 mailmyMail.SendWait(3)'Clear object referenceSet myMail = NothingSet objOutlook = NothingEnd Function |
No comments:
Post a Comment