Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send anonymous emails C#

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

like image 316
Ilya Gazman Avatar asked Jan 18 '23 17:01

Ilya Gazman


1 Answers

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.

like image 94
WoLfulus Avatar answered Jan 24 '23 21:01

WoLfulus