Powershell Set Reply message for user

Posted on 2012-08-16
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, however Im not sure how to do that withing the PS script.

Anyone have any ideas?

Question by:eeamodei

    Accepted Solution

    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 =
    $ToAddress =
    $MessageSubject = "Subject"
    $MessageBody = "This is the body."
    $SendingServer = ""

    ###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

    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!
    LVL 3

    Assisted Solution

    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.
    LVL 6

    Assisted Solution

    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 = ''
    $from ='
    $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

    LVL 6

    Expert Comment

    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

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
    Set OWA language and time zone in Exchange for individuals, all users or per database.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    794 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now