我可以在NetworkCredentials
上发送电子邮件而不提供密码吗?这是我的代码。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
MailMessage Myemail = new MailMessage();
private void btnsendemail_Click(object sender, EventArgs e)
{
SmtpClient myGmailserver = new SmtpClient("smtp.gmail.com",587);
myGmailserver.Credentials = new NetworkCredential("Email ID", "password");
Myemail.From = new MailAddress("Email ID");
Myemail.To.Add(tbTo.Text);
Myemail.Subject = tbsubject.Text;
Myemail.Body = tbmsg.Text;
myGmailserver.EnableSsl = true;
myGmailserver.Send(Myemail);
}
}
在myGmailserver.Credentials = new NetworkCredential("Email ID", "Password");
行上它要求输入该特定电子邮件的密码如果我想向某人发送电子邮件而不知道该电子邮件的密码该怎么办?请回答
答案 0 :(得分:0)
您可以使用此代码
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient();
mail.To.Add(email);
mail.From = new MailAddress("mail@domain.com");
mail.Subject = subject;
mail.IsBodyHtml = true;
mail.Body = message;
SmtpServer.Host = "smtpserver";
SmtpServer.Port = 25;
SmtpServer.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
try {
SmtpServer.Send(mail);
}
catch (Exception ex) {
Debug.WriteLine("Exception Message: " + ex.Message);
if (ex.InnerException != null)
Debug.WriteLine("Exception Inner: " + ex.InnerException);
}
答案 1 :(得分:0)
好的,我得到了我的答案,密码用于凭证而不是收件人..我还有另一件事要问,我在表单中添加timer
并且计时器正在滴答。例如在&# 34; 8:00 pm"一封电子邮件应该自动发送给经理销售报告。有人请帮我。