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 = "test@tachytelic.net" $to = "test@test.com" $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 “test@tachytelic.net” 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("Test@Tachytelic.net", "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.