通过 gmail 发送支持电子邮件
Sent an support e-mail through gmail
我已经实现了通过gmail 发送电子邮件的支持,一切正常。但是这段代码看起来很奇怪,因为例如客户要求程序员通过gmail 支持电子邮件,完成后,程序员将源代码连同程序一起提供给客户。当客户打开它(源代码)时,客户将知道用于制作电子邮件支持的电子邮件以及密码。我怎样才能防止这种情况发生?有什么好的解决方案可以在不在源代码中泄露电子邮件密码的情况下使电子邮件支持?
这是我正在使用的代码:
public void SendRecoverCredentials(string _to)
{
try
{
SmtpClient _smtp = new SmtpClient();
MailMessage _message = new MailMessage();
_message.From = new MailAddress("credentialhelper@gmail.com", "Credential Helper - Support -");
_message.To.Add(new MailAddress(_to, "To whom it may concern"));
_message.Subject = "Credentials Recover";
_message.Body = "Dear to whom it may concern" +
"\n\n\nBelow are your credentials info:" + "\n\n\n\n" + "Please copy the Password and paste it to the program where the Old Password field is." + "\n\n\n\n" + "Username: " + UserInformation.Name + "\nPassword: " + UserInformation.Password +
"\n\n\n\nTo avoid for future messages being moved to the spam or junk folder, please add credentialhelper@gmail.com to be your contact list." +
"\n\n\n*** This is an automatically computer generated e-mail, please do not reply to this message ***";
_smtp.Port = 587;
_smtp.Host = "smtp.gmail.com";
_smtp.EnableSsl = true;
_smtp.UseDefaultCredentials = false;
_smtp.Credentials = new NetworkCredential("support's e-mail address", "support's e-mail password");
_smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
_smtp.Send(_message);
ShowMessageBox("Your message has been successfully sent.", "Success", 2);
}
catch (Exception ex)
{
ShowMessageBox("Message : " + ex + "\n\nEither your e-mail or password incorrect. (Are you using Gmail account?)", "Error", 1);
}
}
谢谢!
简而言之,无法完全按照您的要求进行操作。您无法向客户发送您的凭据并保证它们的安全。将它们编译成 DLL 只会阻止技术上最不熟练的潜在攻击者。
不过,有几种方法可以实现您的目标:
让客户提供他们自己的电子邮件用户名和密码并通过它们发送。这可能是最简单的,因为它不需要太多设置。
使用 OAuth。这与选项 1 基本相同,只是您不让他们提供密码,而是让他们在 Google 页面或其他任何地方单击 "give access"。可能不是要走的路。
创建一个由您控制并存储凭据的 Web 服务,然后让您的应用程序联系该 Web 服务。您的 Web 服务可以确保它是来自您的应用程序的有效请求,然后为您发送电子邮件。虽然这是最好的解决方案,但它可能也需要最多的工作。
另外,虽然和你的问题没有直接关系,但是这段代码是一个严重的问题:
"Username: " + UserInformation.Name + "\nPassword: " + UserInformation.Password
首先,你甚至不应该能够解密任何人的密码。您应该使用单向哈希。为什么会这样,文章很多,这里不再赘述。无论如何,这是个坏主意。此外,通过电子邮件发送敏感信息也不理想。
我已经实现了通过gmail 发送电子邮件的支持,一切正常。但是这段代码看起来很奇怪,因为例如客户要求程序员通过gmail 支持电子邮件,完成后,程序员将源代码连同程序一起提供给客户。当客户打开它(源代码)时,客户将知道用于制作电子邮件支持的电子邮件以及密码。我怎样才能防止这种情况发生?有什么好的解决方案可以在不在源代码中泄露电子邮件密码的情况下使电子邮件支持?
这是我正在使用的代码:
public void SendRecoverCredentials(string _to)
{
try
{
SmtpClient _smtp = new SmtpClient();
MailMessage _message = new MailMessage();
_message.From = new MailAddress("credentialhelper@gmail.com", "Credential Helper - Support -");
_message.To.Add(new MailAddress(_to, "To whom it may concern"));
_message.Subject = "Credentials Recover";
_message.Body = "Dear to whom it may concern" +
"\n\n\nBelow are your credentials info:" + "\n\n\n\n" + "Please copy the Password and paste it to the program where the Old Password field is." + "\n\n\n\n" + "Username: " + UserInformation.Name + "\nPassword: " + UserInformation.Password +
"\n\n\n\nTo avoid for future messages being moved to the spam or junk folder, please add credentialhelper@gmail.com to be your contact list." +
"\n\n\n*** This is an automatically computer generated e-mail, please do not reply to this message ***";
_smtp.Port = 587;
_smtp.Host = "smtp.gmail.com";
_smtp.EnableSsl = true;
_smtp.UseDefaultCredentials = false;
_smtp.Credentials = new NetworkCredential("support's e-mail address", "support's e-mail password");
_smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
_smtp.Send(_message);
ShowMessageBox("Your message has been successfully sent.", "Success", 2);
}
catch (Exception ex)
{
ShowMessageBox("Message : " + ex + "\n\nEither your e-mail or password incorrect. (Are you using Gmail account?)", "Error", 1);
}
}
谢谢!
简而言之,无法完全按照您的要求进行操作。您无法向客户发送您的凭据并保证它们的安全。将它们编译成 DLL 只会阻止技术上最不熟练的潜在攻击者。
不过,有几种方法可以实现您的目标:
让客户提供他们自己的电子邮件用户名和密码并通过它们发送。这可能是最简单的,因为它不需要太多设置。
使用 OAuth。这与选项 1 基本相同,只是您不让他们提供密码,而是让他们在 Google 页面或其他任何地方单击 "give access"。可能不是要走的路。
创建一个由您控制并存储凭据的 Web 服务,然后让您的应用程序联系该 Web 服务。您的 Web 服务可以确保它是来自您的应用程序的有效请求,然后为您发送电子邮件。虽然这是最好的解决方案,但它可能也需要最多的工作。
另外,虽然和你的问题没有直接关系,但是这段代码是一个严重的问题:
"Username: " + UserInformation.Name + "\nPassword: " + UserInformation.Password
首先,你甚至不应该能够解密任何人的密码。您应该使用单向哈希。为什么会这样,文章很多,这里不再赘述。无论如何,这是个坏主意。此外,通过电子邮件发送敏感信息也不理想。