Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I send email from C# without revealing my password?

I found a great way to send email in C#, except for one problem, I have to show my password. If anyone were to disassemble my program, or if I decided to make it open source (which I probably will) they would get the username and password for my gmail account. Is there any way to get around this?

MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
mail.Subject = "Pandora Free-D Message";
mail.Body = "Name: " + C.NameBox.Text + "\n" + "Email: " + C.emailBox.Text + "\n" + C.Message.Text;

SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
SmtpServer.EnableSsl = true;

SmtpServer.Send(mail);

+++++EDIT+++++

hmmm... would localhost work? Anyone know?

like image 202
Sean Avatar asked Sep 30 '26 23:09

Sean


1 Answers

Not if your mail server requires authentication. The program will need to know the password to send mail, and if this program is operating on a computer you don't trust then you can assume the password will be quickly compromised.

You should consider an alternate method, like submitting the mail via a web service or HTTP call to a server under your control, where you can validate the message and then send it to the mail server.

like image 99
cdhowie Avatar answered Oct 02 '26 13:10

cdhowie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!