无需身份验证即可通过powershell发送邮件

无需身份验证即可通过powershell发送邮件,powershell,smtp,sendmail,Powershell,Smtp,Sendmail,我用nant发送邮件,它工作得很好,就像 <mail from="Test@b.c" tolist="A@b.c" subject="Test" mailhost="myhost.mydomain.com" isbodyhtml="true" message= "${Test}"> </mail> 我会得到以下信息: Send-MailMessage : No credentials are available i

我用nant发送邮件,它工作得很好,就像

<mail 
    from="Test@b.c" 
    tolist="A@b.c" 
    subject="Test" 
    mailhost="myhost.mydomain.com"
    isbodyhtml="true"
    message= "${Test}">
</mail>
我会得到以下信息:

Send-MailMessage : No credentials are available in the security package
如果服务器支持,我是否缺少发送邮件而不指定凭据的方法

编辑: 我也尝试过在这里发送匿名邮件,但它只是超时:

使用Powershell v1方法发送邮件,无需验证即可正常工作,如图所示

我的Powershell版本是5,但这显然是要走的路,除非有人有其他想法

$smtpServer = "ho-ex2010-caht1.exchangeserverpro.net"
$smtpFrom = "reports@exchangeserverpro.net"
$smtpTo = $to
$messageSubject = $subject
$messageBody = $body

$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($smtpFrom,$smtpTo,$messagesubject,$messagebody)
我在寻找另一个问题,在这里发现了这个问题。。。。 正如@AngelicCore已经解释的一种方法, 这里是另一个如果有人使用outlook。。。 邮件将出现在您的发件箱中

使用outlook对象

 Try
    {
    #Email structure
    $Outlook = New-Object -ComObject Outlook.Application
    $Mail = $Outlook.CreateItem(0)
    
    #Email Recipients
    $Mail.To = "abc@domain.com;xyz@domain.com"
    $Mail.Cc = "tuv@domain.com; pqr@domain.com"
    
    #Email Subject
    $date = Get-Date -Format g
    $Mail.Subject = "Subject here $date"
    
    #Email Body
    $Mail.Body = "Body Here"
    
    #Html Body
    $Mail.HTMLBody == "<html> HTML Body Here </html>"
    
    #Email Attachment
    $file = "C:\path\xyz.txt"
    $Mail.Attachments.Add($file)
    
    
    $Mail.Send()
    Write-Host -foreground green "Mail Sent Successfully"
    
}
Catch
{
    write-host -foreground red $error[0].Exception.Message 
    
}

pause
exit
试试看
{
#电子邮件结构
$Outlook=新对象-ComObject Outlook.Application
$Mail=$Outlook.CreateItem(0)
#电子邮件收件人
$Mail.To=”abc@domain.com;xyz@domain.com"
$Mail.Cc=”tuv@domain.com; pqr@domain.com"
#电子邮件主题
$date=获取日期-格式g
$Mail.Subject=“此处的主题$date”
#电子邮件正文
$Mail.Body=“此处的Body”
#Html正文
$Mail.HTMLBody==“此处为HTML正文”
#电子邮件附件
$file=“C:\path\xyz.txt”
$Mail.Attachments.Add($file)
$Mail.Send()
写入主机-前台绿色“已成功发送邮件”
}
抓住
{
写入主机-前台红色$错误[0]。异常。消息
}
暂停
出口

如果您的服务器支持未经身份验证的电子邮件,则不指定凭据是正确的。因此,您现在需要指定凭据,或者他们更改了端口的某些内容,您可能需要指定端口。我认为他们没有更改任何内容,因为nant脚本仍然在不指定凭据的情况下运行。我还是powershell新手,因此我不确定是否需要凭据。您运行此powershell命令的上下文是什么?我以管理员身份运行powershell,如果这是您的意思@Bill_Stewart正在ISE和powershell中尝试代码。EXE您的问题似乎在此处得到了回答:
 Try
    {
    #Email structure
    $Outlook = New-Object -ComObject Outlook.Application
    $Mail = $Outlook.CreateItem(0)
    
    #Email Recipients
    $Mail.To = "abc@domain.com;xyz@domain.com"
    $Mail.Cc = "tuv@domain.com; pqr@domain.com"
    
    #Email Subject
    $date = Get-Date -Format g
    $Mail.Subject = "Subject here $date"
    
    #Email Body
    $Mail.Body = "Body Here"
    
    #Html Body
    $Mail.HTMLBody == "<html> HTML Body Here </html>"
    
    #Email Attachment
    $file = "C:\path\xyz.txt"
    $Mail.Attachments.Add($file)
    
    
    $Mail.Send()
    Write-Host -foreground green "Mail Sent Successfully"
    
}
Catch
{
    write-host -foreground red $error[0].Exception.Message 
    
}

pause
exit