如何从命令行发送邮件
原理介绍
PowerShell
PowerShell 中内置了发送邮件的命令 Send-MailMessage
,下面的脚本把密码加密存储在文本里,这样可以不用每次输入密码,参考的是 Secure Password with PowerShell: Encrypting Credentials – Part 1
function psMail {
param(
[Parameter(Mandatory = $true, Position = 0)]
[string] $to = "",
[string] $s = "",
[string] $b = ""
)
$from = "username@domain.com"
$SMTPServer = "smtp.domain.com"
$File = "C:\Users\video\passwd.txt"
$mycredential = new-object -TypeName System.Management.Automation.PSCredential -ArgumentList $from,(Get-Content $File | ConvertTo-SecureString)
Send-MailMessage -from $from -to $to -subject $s -body $b -smtpserver $SMTPServer -Credential $mycredential
}
Mutt, mailx, swaks
-
MTA
-
MDA
Telnet, mail, sendmail
-
SMTP命令
-
TLS的设置
Python
参考 Calibre 发送邮件的方法