Send anonymous emails C#

倾然丶 夕夏残阳落幕 提交于 2019-12-23 14:20:53

问题


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("noreply@mysite.com");
mailMsg.To.Add("user");
mailMsg.CC.Add("cc@ccServer.com");
mailMsg.Bcc.Add("bcc@bccServer.com");
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


回答1:


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 "service@domain.com" or "noreply@domain.com" 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.




回答2:


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 "noreply@mysite.com".

MailMessage mailMsg = new MailMessage();
mailMsg .From = "noreply@mysite.com";
mailMsg .To = "to@toServer.com";
mailMsg .Cc = "cc@ccServer.com"";
mailMsg .Bcc = "bcc@bccServer.com";
mailMsg .Subject = "Subject";
mailMsg .Body = "BodyOfTheMailString";
SmtpMail.Send(mailMsg ); 


来源:https://stackoverflow.com/questions/8954752/send-anonymous-emails-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!