简体   繁体   English

如何在不泄露密码的情况下从C#发送电子邮件?

[英]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. 我找到了一种用C#发送电子邮件的好方法,除了一个问题,我必须显示我的密码。 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. 如果有人要反汇编我的程序,或者如果我决定将其打开(我可能会),他们将获得我的Gmail帐户的用户名和密码。 Is there any way to get around this? 有没有办法解决这个问题?

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

mail.From = new MailAddress("Contact@pandorafreed.com");
mail.To.Add("myemail@gmail.com");
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? 谁知道?

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. 您应该考虑另一种方法,例如通过Web服务或HTTP调用将邮件提交到您控制的服务器,您可以在其中验证邮件,然后将其发送到邮件服务器。

您可以创建Web服务,它将向邮件服务器发送电子邮件。

Why would you have others using your account to send e-mail? 为什么让其他人使用您的帐户发送电子邮件? Let the user use his/her own mailserver and authentication. 让用户使用他/她自己的邮件服务器和身份验证。 Let the user enter those values when installing your program and store it in a configuration file. 让用户在安装程序时输入这些值并将其存储在配置文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM