We help IT Professionals succeed at work.

Powershell Set Reply message for user

eeamodei asked
Hello and thanks in advance!

I am looking for the syntax on how to send an email from a powershell script, but in addition to setting the reply-to address, set a preset reply message when the user clicks on a link.

Im guessing the best way to do this would be to format the message in html with the mailto:xxxx@domain.com, however Im not sure how to do that withing the PS script.

Anyone have any ideas?

Watch Question

Not sure if this will work for you, but when I need to send email from Powershell I create a .ps1 file.

###First, the administrator must change the mail message values in this section
$FromAddress = MailboxReport@neilhobson.com
$ToAddress = administrator@neilhobson.com
$MessageSubject = "Subject"
$MessageBody = "This is the body."
$SendingServer = "server.domain.com"

###Create the mail message
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress,
$MessageSubject, $MessageBody
$Attachment = New-Object Net.Mail.Attachment("./attachment.txt")

###Send the message
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer


hey techpointe,

Thanks for the response. I have that much already and I sending an email and setting the reply-to address is no issue. What im trying to accomplish now is when I user gets that email message, have a hyperlink inside that when the click on it will setup and send a prefabricated message to our helpdesk.

Im trying to automate the reply action.

So that when they click on this link ("Click here to cancel this service"

That upon clicking that link, it will trigger the default email client (Outlook in most cases) to set the reply to address to our helpdesk, set the subject line to whatever I want, and preset the message body for the return message from the user to the help desk.

Thanks again!
I doubt if this automation can be setup to smoothly work, since different email clients would behave differently. In fact, some versions of Outlook would show annoying security pop-ups, while others won't, on trying to send emails from Powershell.

It will be better if the link in the email you send goes to your website (instead of invoking their unknown email client) and appropiate options are offered on your website page.
This is the way i do it. The key things to remember are that your body would need to be written in properly formatted HTML, and the $msg.IsBodyHTML = $true states that the mail is HTML.

$smtpServer = ''

$txt = Get-Content 'C:\Content.txt'
$body = [string]::Join("`r`n",$txt)
$to = 'user@domain.co.uk'
$from = sender@domain.co.uk'
$subject = 'HTML Test'

$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)

$msg.IsBodyHTML = $true
$msg.From = $from
$msg.Subject = $subject
$msg.Body = $body

Open in new window


Sorry, ignore all the:

$txt = Get-Content 'C:\Content.txt'
$body = [string]::Join("`r`n",$txt)

Open in new window

at the top. thats just rubbish from the script I opened to do my testing. thats only really required for Plain text.


hey slidingfox,

I have this format already for sending a message. I am looking to setup a preset message for the user when they click reply though. Akulsh above mentioned this might not be possible due to different types of email clients.

After reading you comment, I was wondering if there was a way to attach the preset message via .txt file to the original message, then when they reply have it use the information in the txt file.

Just a thought, thanks again to all

Explore More ContentExplore courses, solutions, and other research materials related to this topic.