Home > Net >  How to send-mailmessage from displayname?
How to send-mailmessage from displayname?

Time:12-04

I would like to know how do you send mailmessage from displayname? I think we should add New-Object System.Net.Mail.MailMessage to the script but im not sure how to do it..?

$Mail = @{             
                    'To'         = '[email protected]'
                    'From'       = '[email protected]','Lastname, Firstname' #I dont know what to do here
                    'Subject'    = "TEST NOTIFICATION"
                    'SMTPServer' = 'mail.domain.com'
                    'Encoding'   = 'UTF8'
                    'Priority'   = 'High'
                    'Body'       = "Hi, this is a test"
}

Send-MailMessage @Mail

CodePudding user response:

Use the following format: Display Name <sender-address>:

$Mail = @{             
    'To'         = 'someone@domain.com'
    'From'       = 'Lastname, Firstname <me@domain.com>'
    'Subject'    = "TEST NOTIFICATION"
    'SMTPServer' = 'mail.domain.com'
    'Encoding'   = 'UTF8'
    'Priority'   = 'High'
    'Body'       = "Hi, this is a test"
}

Send-MailMessage @Mail
  • Related