我目前正在为我的用户创建一个联系我们页面。在这里,用户可以从任何电子邮件向我发送电子邮件。
using System.Net;
using System.Net.Mail;
OpenFileDialog dlg = new OpenFileDialog();
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
string filename = dlg.FileName;
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress(TextBox1.Text);
mail.To.Add("u@urdomain.com");
mail.Subject = filename;
mail.Body = "Report";
Attachment attachment = new Attachment(filename);
mail.Attachments.Add(attachment);
SmtpServer.Port = 25;
SmtpServer.Credentials = new System.Net.NetworkCredential("me", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
}
此电子邮件只能从 gmail 帐户接收。如何接收来自 yahoo、hotmail 等的电子邮件?对于这一部分SmtpServer.Credentials = new System.Net.NetworkCredential("me", "password");
,我应该写什么?如何获取用户的密码和邮箱?谢谢