使用 powershell 的 AWS SES
AWS SES using powershell
我们已经在我们的环境中实施了 SES。在批处理过程中,我们使用 SES 而不是 SNS 来发送少量自定义电子邮件。这是使用 poweshell 脚本完成的。现在我们想用这封邮件发送附件。目前我们的过程是使用 powershell 完成的。所以我们也想在同一地方实施附件设施。查看发送原始电子邮件的示例,其中创建了内联附件。有人可以向我展示在 powershell 中将现有文件作为附件发送电子邮件的示例吗?
这是一个示例:
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -erroraction silentlyContinue
$file = "D:\filename.txt"
$smtpServer = "127.0.0.1"
$att = new-object Net.Mail.Attachment($file)
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = "emailfrom@test.com"
$msg.To.Add("emailto@test.com")
$msg.Subject = "Notification with attachment"
$msg.Body = "Attached is the file"
$msg.Attachments.Add($att)
$smtp.Send($msg)
$att.Dispose()
这是示例脚本的 link:
Send Email
除此之外,PS 有一个内置的 cmdlet Send-MailMessage:
Send-MailMessage -from "testuser1@email.com" `
-to "testuser2@email.com" `
-subject "Sending the Attachment" `
-body "Sending the attachment." `
-Attachment "filename.txt" -smtpServer smtp.server.com
希望对您有所帮助。
我们已经在我们的环境中实施了 SES。在批处理过程中,我们使用 SES 而不是 SNS 来发送少量自定义电子邮件。这是使用 poweshell 脚本完成的。现在我们想用这封邮件发送附件。目前我们的过程是使用 powershell 完成的。所以我们也想在同一地方实施附件设施。查看发送原始电子邮件的示例,其中创建了内联附件。有人可以向我展示在 powershell 中将现有文件作为附件发送电子邮件的示例吗?
这是一个示例:
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -erroraction silentlyContinue
$file = "D:\filename.txt"
$smtpServer = "127.0.0.1"
$att = new-object Net.Mail.Attachment($file)
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = "emailfrom@test.com"
$msg.To.Add("emailto@test.com")
$msg.Subject = "Notification with attachment"
$msg.Body = "Attached is the file"
$msg.Attachments.Add($att)
$smtp.Send($msg)
$att.Dispose()
这是示例脚本的 link: Send Email
除此之外,PS 有一个内置的 cmdlet Send-MailMessage:
Send-MailMessage -from "testuser1@email.com" `
-to "testuser2@email.com" `
-subject "Sending the Attachment" `
-body "Sending the attachment." `
-Attachment "filename.txt" -smtpServer smtp.server.com
希望对您有所帮助。