2016-11-27 65 views
0

我正在致力於在用戶填寫聯繫表單時向管理員發送聯繫信息。幾乎一切工作正常,但我收到來自同一地址的郵件。 protected void submitButton_Click(object sender, EventArgs e) { System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); mail.To.Add("[email protected]"); mail.From = new MailAddress(EmailTextBox.Text, "Head", System.Text.Encoding.UTF8); mail.Subject = "Query"; mail.SubjectEncoding = System.Text.Encoding.UTF8; mail.Body = "Contact Details" + "<br/> <b>Name:</b>" + Request["app-name"] + " <br/> <b>Email - Address :</b>" + EmailTextBox.Text + "<br/> <b>Description :</b>" + Request["AppointmentMessage"] + "<br/> <b>Contact Number :</b>" + Request["app-num"]; mail.BodyEncoding = System.Text.Encoding.UTF8; mail.IsBodyHtml = true; mail.Priority = MailPriority.High; SmtpClient client = new SmtpClient(); client.Credentials = new System.Net.NetworkCredential("[email protected]", "admin"); client.Port = 587; client.Host = "smtp.gmail.com"; client.EnableSsl = true; try { client.Send(mail); Page.RegisterStartupScript("UserMsg", "<script>alert('Successfully Send...')</script>"); } catch (Exception ex) { Exception ex2 = ex; string errorMessage = string.Empty; while (ex2 != null) { errorMessage += ex2.ToString(); ex2 = ex2.InnerException; } Page.RegisterStartupScript("UserMsg", "<script>alert('Sending Failed...');if(alert){ window.location='SendMail.aspx';}</script>"); } } }從同一封電子郵件獲取郵件SMTP asp.net

在這裏,管理員電子郵件ID是[email protected]。當用戶名爲[email protected]填寫聯繫表格。當他提交表格時,管理員沒有收到來自[email protected]的郵件。相反,他從郵箱[email protected]

幫助表示讚賞。

回答

0

如果這是可能的,我可以發送電子郵件,因爲你不知道你的gmail憑證!

您正在通過管理憑據連接到gmail smtp服務器,gmail將只允許發送電子郵件from field作爲已經配置的管理員或管理員附加電子郵件。不要緊,你設定爲從地址時,Gmail將在寫它防止垃圾郵件..

,如果你需要保留用戶的電子郵件線程,你可以使用CC性能