如何使用 Blat 实用程序从 Windows 批处理文件发送邮件

如何使用 Blat 实用程序从 Windows 批处理文件发送邮件

我想从 Windows 批处理文件发送邮件。这是我的代码:

blat test.log -server smtp.gmx.com -to [email protected] -f [email protected] -s "test mail" -u "[email protected]" -pw "password" -debug -log envois-mails.log -timestamp 

这是我收到的错误:

2014.07.23 14:07:26 (Wed): <<<getline<<< 535 Authentication credentials invalid
2014.07.23 14:07:26 (Wed): The SMTP server did not accept Auth PLAIN value.
Are your login userid and password correct?
2014.07.23 14:07:26 (Wed): >>>putline>>> AUTH LOGIN
2014.07.23 14:07:26 (Wed): <<<getline<<< 334 VXNlcm5hbWU6
2014.07.23 14:07:26 (Wed): >>>putline>>> b3Vzcy56YWltQGdtYWlsLmNvbQ==
2014.07.23 14:07:26 (Wed): <<<getline<<< 334 UGFzc3dvcmQ6
2014.07.23 14:07:26 (Wed): >>>putline>>> aG90bWFpbGhvdG1haWw=
2014.07.23 14:07:26 (Wed): <<<getline<<< 535 Authentication credentials invalid
2014.07.23 14:07:26 (Wed): The SMTP server did not accept Auth LOGIN PASSWD value.
2014.07.23 14:07:26 (Wed): >>>putline>>> QUIT
2014.07.23 14:07:26 (Wed): <<<getline<<< 221 gmx.com Service closing transmission channel

您知道如何解决这个问题吗?

我在用布拉特发送电子邮件

答案1

我认为您可以通过 Powershell 轻松完成此操作。

按着这些次序:

步骤 1 - 打开 CMD(以管理员身份运行)
步骤 2 - 输入 Powershell(按 Enter 键)
步骤 3 - 首先将以下代码复制到记事本中

$EmailFrom = “Your email Address” $EmailTo = “Recipients email Address”
$Subject = “The subject of your email”
$Body = “This is just a test mail to verify the working of CMD”
$SMTPServer = “smtp.gmail.com”
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“username”, “password”);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

步骤 4 - 将您的电子邮件地址更改为发件人的电子邮件
步骤 5 - 更改收件人的电子邮件地址
步骤 6 - 根据需要替换主题和正文 步骤
7 - 用您的凭据替换“用户名”和“密码”。
步骤 8 - 复制上述代码并粘贴到 Windows Powershell 中。

这肯定适用于 gmail。对于其他用户,您可以尝试更改 SMTP 服务器和客户端详细信息。

答案2

正如其他人猜测的那样,这是因为 Gmail 需要 TLS/SSL 连接,而据我所知 Blat 不支持这一点。

我解决了这个问题隧道效果非常好。它设置了一个 TLS/SSL 隧道(在本例中为 gmail SMTP),非 TLS/SSL 启用的应用程序可以使用它来发送电子邮件。我还使用它从其他几个不支持 TLS/SSL 的应用程序发送电子邮件(通过 gmail)。老实说,我不记得配置了,但它非常简单。

您仍然使用您的 gmail 凭据,但替换您的 stunnel 服务器(localhost?-我已在它自己的 Linux 服务器上设置它并使用它 IP,但它是跨平台的,所以我猜它可以在 Windows 上使用 localhost)。

答案3

对于我来说,通过在变量周围使用双引号可以起作用。

我正在使用批处理脚本调用 powershell Send-MailMessage

批处理脚本:send_email.bat

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  -windowstyle hidden -command 'E:\path\send_email.ps1

Pwershell 脚本 send_email.ps1

Send-MailMessage -From "noreply@$env:computername" -To '<[email protected]>' -Subject 'Blah Blah' -SmtpServer  'smtp.domain.com'  -Attachments 'E:\path\file.log' -BODY "Blah Blah on Host: $env:computername "

相关内容