我正在致力於在用戶填寫聯繫表單時向管理員發送聯繫信息。幾乎一切工作正常,但我收到來自同一地址的郵件。 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]
幫助表示讚賞。