• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Tachytelic.net

  • Get in Touch
  • About Me

Specify Display Name when sending Email with PowerShell

October 4, 2019 by Paulie 5 Comments

Sending email with PowerShell is easy with Send-MailMessage. Here is a basic example:

$server = "smtp.sendgrid.net"
$Username ="test"
$Password = ConvertTo-SecureString "Password" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $Username, $Password
$from = "[email protected]"
$to = "[email protected]"
$subject = "Test Message"
$mailbody = @"
Hi Paulie,

This is a test message.

See you soon
"@

Send-MailMessage -smtpServer $server -Credential $credential -Usessl -Port 587 -from $from -to $to -subject $subject -Body $mailbody 

The PowerShell example above sends the email via Sendgrid and works perfectly. But the problem is that the “from” address appears exactly as “[email protected]” and there is no obvious way to specify the display name.

Specifying the Display Name with Powershell

To specify the display name when sending email via Powershell. You can build the from address by creating a System.Net.Mail.MailAddress Like this:

$from = new-object System.Net.Mail.MailAddress("[email protected]", "Paulie")

During my testing whenever I sent a message without a display name, the received message went straight to my “clutter” folder in Outlook. But with the display name included in came to my inbox.

Filed Under: How To Tagged With: Powershell

Reader Interactions

Comments

  1. Carlos Gallardo says

    January 14, 2020 at 4:30 am

    Works!

  2. Tony Sheen says

    September 21, 2021 at 4:32 pm

    Brilliant – thank you for taking the time to post this !

  3. Nikhil Kadi says

    October 22, 2021 at 1:08 pm

    Just putting From mail in below format works just fine too even in Send-MailMessage
    ‘Nikhil Kadi ‘

  4. Nikhil Kadi says

    October 22, 2021 at 1:09 pm

    “Nikhil Kadi “

  5. shafic says

    December 28, 2021 at 4:00 am

    Paul, looking for this, works! thanks

Leave a Reply Cancel reply

Primary Sidebar

Link to my LinkedIn Profile
Buy me a coffee

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 254 other subscribers.

Go to mobile version