How to send automatic mails from QTP (not summary !!) - email

So I know how to send automatic summary mails from QTP.
But this is not the kind of informations I need, in fact I want the LongComments of my tests.
The thing is the content of "test result" mails are exactly what I need, so this is perfect but how to send it automatically at the end of my tests ?
I mean the point of using QTP is automation and I'm not able to automate one of the functionnality of the soft, I'm quite perplexed here...

The following function will work if you have an outlook agent installed and logged in on your test machine. You might have to write case statements based on your test results.
You can also access the mail server directly that way you don't have to install/login an outlook agent.
Function sendemail
Set objOutlook = CreateObject("Outlook.Application")
Set sndmail= objOutlook.CreateItem(0)
'Set properties
sndmail.To = "abc#gmail.com"
sndmail.CC = "abc#gmail.com; def#yahoo.com"
sndmail.Subject = "Sending mail"
sndmail.Body= "Test Contents"
sndmail.Attachments.Add("C:\Test.txt") 'Path of the file
'Send the mail
sndmail.Send
'Clear object
Set sndmail= Nothing
Set objOutlook = Nothing
End Function

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

Related

Outlook PowerShell script to set Direct Replies To address

I have an automated powershell script to send alert email. Since the alert are send from a generic email.. i want people replying to the email to goto another email address say efg#outlook.com.
$Outlook = New-Object -comObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = "asd#outlook.com"
$Mail.Subject = "Alert Email"
$Mail.HtmlBody = $HTML
$Mail.Headers.Add("In-Reply-To", "<efg#outlook.com>")
$Mail.display()
$Mail.send()
somehow this is not working.
Managed to get it from the below
ReplyRecipientNames
$Mail.ReplyRecipientNames = "efg#outlook.com"
Firstly, MailItem object does not expose the Headers property - your script will stop rigth there.
If you want to redirect replies to a different address, use Mail.ReplyRecipients.Add("efg#outlook.com")
You can use the MailItem.SendUsingAccount property which allows setting up an Account object that represents the account under which the MailItem is to be sent. Be aware, the account should be configured in Outlook in that case. For example, here is a VBA code sample which shows how to set up the property:
Sub SendUsingAccount()
Dim oAccount As Outlook.account
For Each oAccount In Application.Session.Accounts
If oAccount.AccountType = olPop3 Then
Dim oMail As Outlook.MailItem
Set oMail = Application.CreateItem(olMailItem)
oMail.Subject = "Sent using POP3 Account"
oMail.Recipients.Add ("someone#example.com")
oMail.Recipients.ResolveAll
Set oMail.SendUsingAccount = oAccount
oMail.Send
End If
Next
End Sub
For Exchange users you may also consider using the MailItem.SentOnBehalfOfName property which is represented by a string indicating the display name for the intended sender of the mail message.
But also you may be interested in the MailItem.ReplyRecipients property which returns a Recipients collection that represents all the reply recipient objects for the Outlook item. The following article which I wrote for the technical blog shows how to deal with a recipient collection, see How To: Fill TO,CC and BCC fields in Outlook programmatically for more information.

New Email Dialogue in Outlook

Is it possible to create a new email with redemption and open outlook new email dialogue, without outlook running.
I know how to create an email, is it just a case of creating the temporary email save it as an msg, then process start, or can I achieve this via another method.
Dim Session As RDOSession = RedemptionLoader.new_RDOSession
Dim Msg = Session.GetMessageFromMsgFile(strPath & "" & strFilename, True)
Msg.MessageClass = "IPM.Note"
You can, just call RDOMail.Display(true/false) (true for for modal display). Keep in mind that MAPI forms used to show the message are implemented by outlook.exe, so it will launch anyway if it is not running.
You can create new items without Outlook running on the system (but it should be installed with a mail profile configured, or at least the MAPI runtime should be installed):
' create a new session
Dim Session As RDOSession = RedemptionLoader.new_RDOSession
Session.Logon
Set Folder = Session.GetDefaultFolder(olFolderInbox)
Set Msg = Inbox.Items.Add("IPM.Note")
Msg.BCC = "eugene#astafiev.vvv"
Msg.Subject = "test"
Msg.Display()

Forwarding multiple emails as attachment into a new email from excel vba

Can anyone help me with excel vba code to send multiple/specific emails that are present in my inbox as an attachment in a new mail to someone I want.
so basically what I am asking for is if I go to my outlook express inbox and select lets say three mails and then click on the forward button on the ribbon it will create a new mail item with the mails that were selected as an attachment. I want this to be automated from excel vba.
Please any help will be highly appreciated.
Regards,
Premanshu
I have found answer for my question after some more search from one online forum/community and have been able to modify that according to my need. Posting the code below for anyone's reference and also the link for the original post that I used and modified for my purpose.
Sub ForwardSelectedItems()
On Error Resume Next
Dim myolApp As Outlook.Application
Dim objItem As Outlook.MailItem
Set objOL = CreateObject("Outlook.Application")
If objOL.ActiveExplorer.Selection.count = 0 Then
MsgBox ("No item selected")
Exit Sub
End If
For Each objItem In objOL.ActiveExplorer.Selection
Set objMsg = objItem.Forward()
With objMsg
.Display
For Each itm In objOL.ActiveExplorer.Selection
.Attachments.Add itm, olEmbeddeditem
Next itm
.Subject = "example"
.To = "example#example.com"
.Body = “”
.Send
End With
Exit For
Next
Set objItem = Nothing
Set objMsg = Nothing
End Sub
the link for the popst I refered to is:-
Forwarding Outlook Item as attachment and adding it to a category in the same VBA macro
Thank you all.
Regards,
Premanshu

Send an email from access via Lotus iNotes installed on intranet

I just need to be pointed in the right direction, on how
to send an email using VBA. I have Lotus as an email system which is embedded into our intranet system.
As a try, this code prepares an email and send it via Lotus (installed on pc) :
Dim ns As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim sender, recipient As String
'sender = Forms![LogIn]![TxtEmail]
If (Not IsNull(DLookup("Email", "Users", "UserName ='" & Me.Affectation.Value & "'"))) Then
recipient = DLookup("Email", "Users", "UserName ='" & Me.Affectation.Value & "'")
MsgBox "recipient *" & recipient & "*"
Else
MsgBox " recipient null"
End If
If Not (ns Is Nothing) Then
Call ns.InitializeUsingNotesUserName("CN=MyuserName/O=Cmpany", "password")
Set db = ns.GetDatabase("ServerName", "mail\MyuserName.nsf", False)
If (Not (db Is Nothing)) Then
Set doc = db.CreateDocument()
doc.Form = "Memo"
doc.SendTo = recipient
doc.subject = "Email Subject"
Dim rt As NotesRichTextItem
Set rt = doc.CreateRichTextItem("Body")
rt.AppendText ("Body text")
doc.Send (False)
Set rt = Nothing
Set doc = Nothing
MsgBox "Message Sent."
Else
MsgBox "db Is Nothing"
End If
Set db = Nothing
Set ns = Nothing
Else
MsgBox "ns Is Nothing"
End If
My question here is how set this code to make the target Lotus the one on our intranet: my login is such "39398C#mycompany.com" and the application is accessed by "http://mail.mycompany.com/mail/username.nsf..."
Unfortunately this is not possible this way. This "embedded" Lotus Notes as you call it is a simple website. It is called "iNotes" and does not have any dlls installed on your client (unless you install the ActiveX control for IE, but that does not help anything with your problem).
For sending eMails via iNotes you need a complete new method and you need your Domino administrator to help you with it: You could either use a webservice to send your mail (this has to be enabled on the server) or you can use DIIOP (again: DIIOP- Task has to be loaded on server).
To at least compose an email, you could use the mailto: protocol, but you need to set iNotes to be your mailto- protocol- handler:
Open Internet Explorer browser and log into iNotes (http://mail.mycompany.com/mail/username.nsf). Please note that this option is not available at this time to Firefox browser users.
Click the "Preferences" button located in the top right corner.
Find "Default Mail Client" section on the "Basics" tab of the iNotes preferences.
Click the button "Make Default".
Using this approach you cannot send the mail directly but need the user to press "Send".
I am not sure what you mean by "I have Lotus as an email system which is embedded into our intranet system".
You need the Notes client installed locally to be able to use COM in your own code. Use the ID file (must be local in the Notes Data directory) for your corporate account amd point to the server on the network for your mailfile.
But you can't point your program to a iNotes instance on a web server, it has to be on a Domino server accessed with a Notes client.
What you could do is to create a new web application on the server, where you have an agent that will read HTTP POST data, create an email and send it out.
Then you simply make a HTTP post from your application.
Here are a couple of blog entries I wrote that might help you:
http://blog.texasswede.com/free-code-class-to-read-url-name-value-pairs/
http://blog.texasswede.com/parse-url-in-domino-agent/
You should probably change your code to send mail via SMTP instead of using the Notes API objects. Microsoft provides an object model called CDO that I think will help you. See the answer to theis question for details. You will just need the hostname or IP address information to connect to a Domino server in your infrastructure that supports inbound SMTP.
Not sure about it, because that code is pretty old as we know use Outlook and I haven't use it in a long while, but that might be some insight :
I seem to remember that if you add doc.From = ns.CommonUserName, this will choose your session automatically!
And the full code :
Dim session As Object
Dim db As Object
Dim doc As Object
Dim attachme As Object
Dim EmbedObj As Object
Dim attachment() As String
Dim i As Integer
Set session = CreateObject("notes.notessession")
Set db = session.GetDatabase("", "")
Call db.OPENMAIL
Set doc = db.CreateDocument
With doc
.Form = "Memo"
.sendto = MailDestinataire
'.copyto = MailDestinataire2
.Subject = Sujet
.Body = CorpsMessage
.From = session.CommonUserName
.posteddate = Now
.SaveMessageOnSend = True
End With

How to Generate an E-mail Message in Microsoft Outlook Outbox in VB6?

I need to send e-mails from my application. But, instead of sending the e-mails directly from through SMTP, I'd like to send it through Microsoft Outlook. So...
How to Generate an E-mail Message in Microsoft Outlook Outbox in VB6?
This support page from Microsft has examples.
Send a message to your new contact.
Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)
' Fill out & send message...
olMail.To = olItem.Email1Address
olMail.Subject = "About our meeting..."
olMail.Body = _
"Dear " & olItem.FirstName & ", " & vbCr & vbCr & vbTab & _
"I'll see you in 2 minutes for our meeting!" & vbCr & vbCr & _
"Btw: I've added you to my contact list."
olMail.Send
Use COM automation. This KnowledgeBase article explains how to do it from VBA, it's exactly the same in VB6. The References command is on the Project menu in VB6 not the Tools menu, I think that's the only difference. EDIT: This KnowledgeBase article explains how to do it in VB6. Kudos to Shoban for this, upvote his answer not mine!
I think the MSDN topic Automating Outlook from a Visual Basic applications is also worth mentioning just for Microsoft's typo in the title!
Add a project reference to the Microsoft Outlook X Object Library
Then, in a form, module, class, or whatever ... I chose a button_click event.
Private Sub Command1_Click()
Dim objOutlook As Outlook.Application
Dim objMail As MailItem
Dim strToAddress As String
Dim strSubject As String
Dim strBody As String
Set objOutlook = New Outlook.Application
Set objMail = Outlook.CreateItem(olMailItem)
strToAddress = "me#mydomain.com"
strSubject = "VB6 test email"
strBody = "This is a test email sent from VB6"
With objMail
.To = strToAddress
.Subject = strSubject
.BodyFormat = olFormatPlain
.Body = strBody
End With
MsgBox "outlook security will now complain as I try to resolve your email addresses against your address book"
objMail.Recipients.ResolveAll
objMail.Save
Set objMail = Nothing
Set objOutlook = Nothing
MsgBox "look in your drafts folder for the new email"
'Thank you, I'm here all week, try the Veal. Good night.
End Sub