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 [email protected].
$Outlook = New-Object -comObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = "[email protected]"
$Mail.Subject = "Alert Email"
$Mail.HtmlBody = $HTML
$Mail.Headers.Add("In-Reply-To", "<[email protected]>")
$Mail.display()
$Mail.send()
somehow this is not working.
Managed to get it from the below ReplyRecipientNames
$Mail.ReplyRecipientNames = "[email protected]"
CodePudding user response:
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 ("[email protected]")
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.
CodePudding user response:
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("[email protected]")