Powershell Set Reply message for user

Posted on 2012-08-16
Medium Priority
Last Modified: 2012-08-21
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?

Question by:eeamodei

Accepted Solution

Chuck Cobern earned 668 total points
ID: 38302332
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

Author Comment

ID: 38302374
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!

Assisted Solution

Akulsh earned 668 total points
ID: 38302561
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.
What Security Threats Are We Predicting for 2018?

Cryptocurrency, IoT botnets, MFA, and more! Hackers are already planning their next big attacks for 2018. Learn what you might face, and how to defend against it with our 2018 security predictions.


Assisted Solution

slidingfox earned 664 total points
ID: 38304002
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


Expert Comment

ID: 38304007
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.

Author Comment

ID: 38311584
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Screencast - Getting to Know the Pipeline

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question