【发布时间】:2019-12-11 22:10:34
【问题描述】:
我对 PowerShell 了解不多,但我在 Stack Overflow 中找到了有关如何发送带有附件的电子邮件的代码。我想知道是否可以对其进行一些更改,以便我可以发送两个附件而不是一个。我想在不使用 ZIP 或 RAR 压缩的情况下发送文件:
附件: "C:\Users\ricar\Desktop\impressora.txt" "C:\Users\ricar\Desktop\impressora2.txt"
$Username = "myemail@sapo.pt";
$Password = "mypassword";
$path = "C:\Users\ricar\Desktop\impressora.txt";
function Send-ToEmail([string]$email, [string]$attachmentpath){
$message = new-object Net.Mail.MailMessage;
$message.From = "myemail@sapo.pt";
$message.To.Add($email);
$message.Subject = "Hello how are you";
$message.Body = "Is this really going to happen?????";
$attachment = New-Object Net.Mail.Attachment($attachmentpath);
$message.Attachments.Add($attachment);
$smtp = new-object Net.Mail.SmtpClient("smtp.sapo.pt", "587");
$smtp.EnableSSL = $true;
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$smtp.send($message);
write-host "Mail Sent" ;
$attachment.Dispose();
}
Send-ToEmail -email "myfriend@yahoo.com.br" -attachmentpath $path;
【问题讨论】:
标签: powershell