【发布时间】:2014-04-16 14:39:25
【问题描述】:
我想通过 c# 桌面应用程序发送电子邮件,用户可以使用此代码默认发送电子邮件
SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("email@gmail.com", "Display Name");
mail.To.Add(EmailTo.Text.Trim());
mail.Subject = EmailSubject.Text;
mail.Body = EmailText.Text;
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(file);
mail.Attachments.Add(attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("email@gmail.com", "Password");
SmtpServer.EnableSsl = true;
而且它工作得很好。但我想让用户手动设置他的 SMTP 设置,所以我会让他输入他的服务器名称、用户名和密码作为他的电子邮件地址,但是我如何使用他的 SMTP 服务器用户名和密码?我还需要做什么才能做到这一点????
【问题讨论】: