发送匿名电子邮件 C#
您好,我想使用 c# 向我的用户发送密码验证,并且我希望保护我的邮箱免受垃圾邮件。我该怎么做?
一直在尝试这样做,但它不起作用:
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
smtpClient.EnableSsl = true;
smtpClient.Timeout = 10000;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential("login", "password");
MailMessage mailMsg = new MailMessage();
mailMsg.From = new MailAddress("[email protected]");
mailMsg.To.Add("user");
mailMsg.CC.Add("[email protected]");
mailMsg.Bcc.Add("[email protected]");
mailMsg.Subject = "Subject";
mailMsg.Body = "BodyOfTheMailString";
smtpClient.Send(mailMsg);
Console.WriteLine("Mail sent");
我向其发送此电子邮件的用户,将我的 Gmail 帐户作为发件人
Hi I want to send password validation to my users using c#, and I wish to protect my mail box getting spammed. How do I do that?
Been trying to this and it's not working:
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
smtpClient.EnableSsl = true;
smtpClient.Timeout = 10000;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential("login", "password");
MailMessage mailMsg = new MailMessage();
mailMsg.From = new MailAddress("[email protected]");
mailMsg.To.Add("user");
mailMsg.CC.Add("[email protected]");
mailMsg.Bcc.Add("[email protected]");
mailMsg.Subject = "Subject";
mailMsg.Body = "BodyOfTheMailString";
smtpClient.Send(mailMsg);
Console.WriteLine("Mail sent");
The user i am sending this email to, getting my gmail account as the sender
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是 C# 的任务,也不是您的邮件正文:它是您的邮箱配置。
如果这只是为了电子邮件验证,您可以随时创建一个新电子邮件,例如“[email protected] ]”或“[email protected]" 用于发送这些验证邮件,然后将此邮箱设置为忽略传入的邮件消息。
此外,如果您尝试使用未注册到您的服务器的电子邮件发送消息,服务器可能会拒绝您的请求。
This is not C#'s task, neither the body of your message: its your mailbox configuration.
If this is just for email validation, you can always create a new email like "[email protected]" or "[email protected]" for sending these verifications messages and then set this mailbox to ignore incoming messages.
Also if you try to send messages using emails that are not registered into your server, the server can deny your request.
更新:
您最初应该提到您正在使用 gmail 的 smtp。为了防止人们发送垃圾邮件,无论您在“发件人”属性中写入什么内容,gmail 始终将“发件人”设置为您的电子邮件地址。
将 MailMessage 上的发件人地址设置为“[电子邮件受保护]”。
UPDATE:
You should initially have mentioned that you are using gmail's smtp. To prevent people to send spam gmail always sets from to your emailaddress regardless of what you write in the From property.
Set the From address on the MailMessage to "[email protected]".