简体   繁体   English

从同一电子邮件SMTP asp.net获取邮件

[英]getting mail from same email SMTP asp.net

I am working on sending contact information to admin when user fills contact form. 当用户填写联系表格时,我正在将联系信息发送给管理员。 Almost everything is working fine but, I am receiving mail from the same address. 几乎一切正常,但是,我从同一地址收到邮件。 protected void submitButton_Click(object sender, EventArgs e) { System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); mail.To.Add("admin@gmail.com"); 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("admin@gmail.com", "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>"); } } }

Here, the admin email id is admin@gmail.com. 在这里,管理员电子邮件ID为admin@gmail.com。 When an user named user@gmail.com fills up contact form. 当名为user@gmail.com的用户填写联系表时。 When he submits that form, the admin is not receiving mail from the user@gmail.com . 当他提交该表单时,管理员未从user@gmail.com接收邮件。 Instead he gets mail from admin@gmail.com 相反,他从admin@gmail.com接收邮件

Help is appreciated. 感谢帮助。

If this is possible I can send emails as you without knowing your gmail credentials! 如果可以的话,我可以在不知道您的Gmail凭据的情况下向您发送电子邮件!

You are connecting to gmail smtp server from admin credentials, gmail will allow only to send email from field as admin or admin attached emails which already configured. 您正在连接到由管理员凭据Gmail的SMTP服务器,Gmail将只允许发送电子邮件from field作为已配置管理员或管理员连接电子邮件。 It doesn't matter what you set as from address, gmail will over-write it for prevent spamming.. 不管您从地址设置为什么,gmail都会覆盖它以防止垃圾邮件。

if you need to keep user in the email thread, you can use To or CC properties 如果需要将用户保留在电子邮件线程中,则可以使用“ 收件人”或“ 抄送”属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM