当文本有价值时,我发送到电子邮件,并自动回复用户,我想为我自己发送一个来获取txtcontent
内容为什么不发送邮件的内容?
if (txtMessagesubject.Text != "" && txtContent.Text != "")
{
MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress(txtEmail.Text));
msg.From = new MailAddress("TheDonkeySkin@gmail.com");
msg.Subject = txtMessagesubject.Text;
string body = "thx we are receive you contact";
msg.Body = body;
msg.IsBodyHtml = true;
msg.Priority = MailPriority.Normal;
SmtpClient smtp = new SmtpClient();
System.Net.NetworkCredential myCredential = new System.Net.NetworkCredential("TheDonkeySkin@gmail.com", "password");
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.Credentials = myCredential;
smtp.EnableSsl = true;
try
{
smtp.Send(msg);
contactsupport.Attributes.Add("style", "display:none;");
thankQ.Attributes.Add("style", "display:block;");
txtEmail.Text = "";
txtMessagesubject.Text = "";
txtContent.Text = "";
}
catch (Exception ex)
{
errorMsgReturn.Text = "Please try again";
}
/************************************/
MailMessage msgself = new MailMessage();
msgself.To.Add(new MailAddress("TheDonkeySkin@gmail.com"));
msgself.From = new MailAddress(txtEmail.Text);
msgself.Subject = txtMessagesubject.Text;
string body2 = txtContent.Text;
msgself.Body = body2;
msgself.IsBodyHtml = true;
msgself.Priority = MailPriority.Normal;
SmtpClient smtpself = new SmtpClient();
System.Net.NetworkCredential myCredentialself = new System.Net.NetworkCredential("TheDonkeySkin@gmail.com", "password");
smtpself.Host = "smtp.gmail.com";
smtpself.Port = 587;
smtpself.UseDefaultCredentials = false;
smtpself.Credentials = myCredentialself;
smtpself.EnableSsl = true;
try
{
smtpself.Send(msgself);
}
catch
{
}
答案 0 :(得分:0)
当您发送第一封电子邮件时,您有:
txtEmail.Text = "";
和第二
msgself.From = new MailAddress(txtEmail.Text);
所以
msgself.From = ""