我正在尝试使用 c# App 发送电子邮件,下一个代码正在运行.
I'm trying to send an email using c# App, the next code is working.
SmtpClient MailClient = new SmtpClient("smtp.gmail.com");
MailClient.EnableSsl = false;
MailClient.Credentials = new NetworkCredential("Ryan.White", "Password");
MailMessage Msg = new MailMessage();
Msg.From = new MailAddress("Sender.name@gmail.com");
Msg.To.Add(new MailAddress("Ryan.White@gmail.com"));
Msg.Subject = "testSub";
Msg.Body = "testBody";
MailClient.Send(Msg);
但 Gmail 的 SMTP 服务器将 gmail 电子邮件地址 (Ryan.White@gmail.com) 作为发件人,
But Gmail's SMTP server puts gmail e-mail address (Ryan.White@gmail.com) as the sender,
不管 MSG.FROM 地址 (Sender.name@gmail.com).
regardless the MSG.FROM address (Sender.name@gmail.com).
是否可以使用 C#/.NET 发送电子邮件并控制发件人地址?
或者发送一封不经过身份验证的电子邮件?
Or alternatively send an email without authentication?
我知道在 UNIX 中,您可以在邮件"命令中控制发件人地址.
I know that in UNIX you can control the sender address in 'Mail' command.
Gmail 这样做是出于安全原因,否则垃圾邮件发送者很容易发送看似来自虚假地址的电子邮件.
Gmail is doing that for security reasons, otherwise it would be easy for spammers to send emails that appear to come from fake addresses.
您已正确编码,C# 将尝试将发件人地址设置为 Sender.Name@gmail.com,但 SMTP 服务器拥有最终决定权.如果您有权以其他用户的身份发送邮件,这将起作用,例如在 Exchange 服务器环境中您被验证为管理员的情况.但是,Gmail 似乎不允许这样做.您需要以 Sender.name 身份登录才能以该用户身份发送电子邮件.
You have coded this correctly, and C# will attempt to set the from address as Sender.Name@gmail.com, but the SMTP server has the final say. If you had authorization to send as another user, this would work, like in the case of an Exchange server environment where you are authenticated as an admin. However, Gmail doesn't seem to allow this. You would need to login as Sender.name to be able to send emails as that user.
这篇关于使用 SMTP 发送电子邮件并控制发件人地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!