我正在试图弄清楚如何在Send-MailMessagegmail中使用PowerShell V2 .
这是我到目前为止所拥有的.
$ss = New-Object Security.SecureString
foreach ($ch in "password".ToCharArray())
{
$ss.AppendChar($ch)
}
$cred = New-Object Management.Automation.PSCredential "uid@domain.com", $ss
Send-MailMessage -SmtpServer smtp.gmail.com -UseSsl -Credential $cred -Body...
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn
more at
At foo.ps1:18 char:21
+ Send-MailMessage <<<< `
+ CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
+ FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
Run Code Online (Sandbox Code Playgroud)
我做错了什么,或者还Send-MailMessage没有完全出炉(我在使用CTP 3)?
一些额外的限制
我收到了这个错误
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. e17sm974159fak.34
Run Code Online (Sandbox Code Playgroud)
Web.config文件
<mailSettings>
<smtp deliveryMethod="Network"
from="emailaccount@gmail.com">
<network defaultCredentials="false" host="smtp.gmail.com" port="587"
userName="emailaccount@gmail.com" password="12345678" />
</smtp>
</mailSettings>
Run Code Online (Sandbox Code Playgroud)
代码文件
public void Submit()
{
EnsureCurrentlyValid();
// Send via email
var message = new StringBuilder();
message.AppendFormat("Date: {0:yyyy-MM-dd hh:mm}\n", DateTime.Now);
message.AppendFormat("Email from: {0}\n", Name);
message.AppendFormat("Email: {0}\n", Email);
message.AppendFormat("Message: {0}\n", Message);
SmtpClient smtpClient = new SmtpClient();
MailMessage m = new MailMessage(
"visitor@mydomain.com", …Run Code Online (Sandbox Code Playgroud) 我正在尝试从 PowerShell 脚本发送电子邮件,但似乎无法通过我的 SMTP 服务器正确验证。
$fromEmail = 'local@example.com';
$toEmail = 'remote@example.net';
$mailUser = 'myUsername';
$mailPassword = 'myPassword';
$smtpServer = 'smtp.example.com';
$smtpPort = 587;
$content = 'Email message content';
$subject = 'Email message subject';
$credentials = New-Object System.Net.NetworkCredential $mailUser, $mailPassword;
$server = New-Object System.Net.Mail.SmtpClient $smtpServer, $smtpPort;
$server.UseDefaultCredentials = $false;
$server.EnableSSL = $true;
$server.Credentials = $credentials
$server.Send($fromEmail, $toEmail, $subject, $content);
Run Code Online (Sandbox Code Playgroud)
当我尝试在 powershell 提示符下运行上述内容时,会导致指定中继访问被拒绝的错误。
Exception calling "Send" with "4" argument(s): "Client does not have permission to submit mail to this server. The
server …Run Code Online (Sandbox Code Playgroud) 我在许多论坛上进行了搜索,他们确实解释了如何执行此操作,但是技术语言太难理解了,因为我是Powershell的新手。我想逐步向我解释(婴儿步骤)。我想在批处理文件(.bat)中运行此powershell命令。我有一个每周执行robocopy备份的批处理文件,我希望该批处理文件在备份完成后向我发送电子邮件。我唯一的问题是凭据,我得到一个弹出框,询问用户名和密码。当我确认此信息时,电子邮件将成功发送。这是我所拥有的;
使用:Powershell V2.0 Windows 7 Ultimate
Powershell -command send-mailmessage -to emailadress@provider.com -from emailaddress@provider.com -smtp smtp.broadband.provider.com -usessl -subject 'backup complete'
Run Code Online (Sandbox Code Playgroud) powershell ×3
email ×2
batch-file ×1
c# ×1
command ×1
gmail ×1
security ×1
smtp ×1
smtpclient ×1