Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send mail via powershell without authentication

I was using nant to send mail and it is working fine - something like

<mail 
    from="[email protected]" 
    tolist="[email protected]" 
    subject="Test" 
    mailhost="myhost.mydomain.com"
    isbodyhtml="true"
    message= "${Test}">
</mail>

I didn't have to use any kind of authentication.

Now when using powershell it seems I am forced to use authentication - something like this would fail:

Send-MailMessage -To $to -From $from -Subject "Test" –Body “Test (body) -SmtpServer "myhost.mydomain.com"

I would get the following message:

Send-MailMessage : No credentials are available in the security package

Am I missing some way to send mails without specifying credentials if the server supports that?

Edit: I've also tried the answer here to send anonymous mails but it just times out: send anonymous mails using powershell

like image 296
AngelicCore Avatar asked Aug 30 '25 17:08

AngelicCore


1 Answers

Sending mails using Powershell v1 method works fine without authentication as shown here

My Powershell version is 5 yet this is apparently the way to go, unless someone has another idea.

$smtpServer = "ho-ex2010-caht1.exchangeserverpro.net"
$smtpFrom = "[email protected]"
$smtpTo = $to
$messageSubject = $subject
$messageBody = $body

$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($smtpFrom,$smtpTo,$messagesubject,$messagebody)
like image 120
AngelicCore Avatar answered Sep 02 '25 16:09

AngelicCore