Outlook PowerShell script to set Direct Replies To address - powershell

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.

Related

Reading MSG file from outlook via powershell .. how to get email address?

Fairly simple script at the moment I simply need to get the recipients email address out of a msg file, apparently there's not an easy way to parse it in text so I've used the following code, but I only get a name such as 'Joe Smith' when reading the message not joe.smith#mydomain.com
Any ideas?
Thanks!
$outlook = New-Object -comobject outlook.application
$msg = $outlook.CreateItemFromTemplate("c:\MyMessage.msg")
$msg | Select to
You need to access the Recipients collection and read the Recipient.Address property for the items in that collection. You also might want to use Application.Session.OpenSharedItem instead of CreateItemFromTemplate.

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

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

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

How to make an excel table that automatically sends email to someone on his birthday?

I need to write a formula that recognizes when someone's birthday is and trigger www.zapier.com.]
I have a birthday-recognition formula that creates a "send email" hyperlink, but I need it to be automatically sent (and delayed to 10am) non-interactively. I also did something in VBA but I only managed to write code that sends that message to 1 person.
Here's the working birthday-recognition formula. Client names are in column C8:C100, emails are in D8:D100, DOBs are in E8:E100 and the "send mail" hyperlinks are in F:100.
=IF(TEXT(E13;"d.m")=TEXT(TODAY();"d.m");HYPERLINK("mailto:"&D13&"? subject="&$D$2&"&body="&SUBSTITUTE(SUBSTITUTE($E$3;"$";C13);"#";$D$4);"pošalji čestitku");"")
"pošalji čestitku" = send mail (croatian language)
VBA code:
Private Sub CommandButton1_Click()
POŠALJIROĐENDANSKEČESTITKE
End Sub
Public Function POŠALJIROĐENDANSKEČESTITKE()
Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")
Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)
olMail.To = Cells.Range("D8:D1000")
olMail.subject = "Sretan rođendan"
olMail.Body = "Poštovani," & vbCrLf & vbCrLf & "Želimo Vam sretan rođendan"
& vbCrLf & vbCrLf & "Sve najbolje," & vbCrLf & vbCrLf & "svinaweb"
olMail.Send
End Function
This code just sends the message to one email when I click on the command button, but as I said I want it to be sent to every person that has a birthday today and to delay the sending of the emails to 10am instead of midnight.
I am using Excel 2013.
The Recipients property of the MailItem class returns a Recipients collection that represents all the recipients for the Outlook item.
The Recipients class provides the the Add method to create a new Recipient object and add it to the Recipients object. The Type property returns or sets the type of recipient. It can be one of the following OlMailRecipientType constants: olBCC, olCC, olOriginator, or olTo.
So, you can send the single email to all people. You just need to add them to the Recipients collection. Or, if you need to have individual message bodies, you can create separate email messages.
The DeferredDeliveryTime property of the MailItem class allows to set a Date indicating the date and time the mail message is to be delivered.

Sent Outlook draft from other Computer

I got eMail account on Exchange Server and that situation. I start on my
Computer outlook (connected to this Email) run this code. The Email will created and saved in drafts.Thats working fine.
Than i take my notebook (connected to the same account) and try to sent it from the drafts. Get error wrong email address but it looks like correct address "test#test.com". If i delete this and type one more time the same address from my keyboard "test#test.com" it works.I got Windows 7 ,`Outlook 2013 with disabled Cached Exchange Mode.
_OutlookApplication = New Microsoft.Office.Interop.Outlook.Application
Dim mailItem = CType(_OutlookApplication.CreateItem(OlItemType.olMailItem), MailItem)
mailItem.Recipients.Add("test#test.com")
mailItem.Body ="Text"
mailItem.Subject = "Subject"
mailItem.Save()
Why should i retype the address? and how can i fix it?
_OutlookApplication = New Microsoft.Office.Interop.Outlook.Application
Dim mailItem = CType(_OutlookApplication.CreateItem(OlItemType.olMailItem), MailItem)
Dim _TestRec As Recipient
_TestRec=mailItem.Recipients.Add("test#test.com")
_TestRec.AddressEntry.Address = "test#test.com"
mailItem.Body ="Text"
mailItem.Subject = "Subject"
mailItem.Save()
The problem is - mailItem.to setting only the Display Name. Had only to create a Recipient and set Recipient.AddressEntry.Address mailItem.Recipients.Add("test#test.com")