adding custom x-headers to e-mails using the send-mailmessage powershell RRS feed

  • Question

  • Hi,

    I am sending e-mails through Win 2012 task scheduler using PowerShell send-mailmessage command, I would like to add a custom x-header to these e-mails, how can I do this? Thanks

    Thursday, December 29, 2016 11:57 AM

All replies

  • What is it that you are calling a custom email header.  A mail message has a subject and a body.  It does not have "headers".

    The x-headers that are added to mail messages are added by the mail servers that have forwarded the mail.  They are not controlled by the PowerShell mail client.

    If you use a custom SMTP mailer that allows adding headers you can do this but it is not a part of Send-MailMessage.


    • Edited by jrv Thursday, December 29, 2016 12:29 PM
    Thursday, December 29, 2016 12:27 PM
  • You can use the basic mail type to add custom headers to a message:

    D:\scripts> $m = New-Object System.Net.Mail.MailMessage
    D:\scripts> $m.headers.Add('x-test','test of custom header')
    D:\scripts> $m.headers
    D:\scripts> $m.headers['x-test']
    test of custom header


    • Edited by jrv Thursday, December 29, 2016 12:35 PM
    • Proposed as answer by Hello_2018 Friday, December 30, 2016 3:01 AM
    Thursday, December 29, 2016 12:34 PM
  • Thank-you, this works great. thanks again - too bad this could not work in Send-MailMessage.
    Thursday, December 29, 2016 5:01 PM