There is feedback, the user must fill in the required field Email. When you click the send button, the letter is sent to support@domain.com.
Task: In the incoming letter in the field "from whom" there was a client's email (Email), and not sender@domain.com.
Purpose: Further, the user in the mailer clicked the "answer" button and began correspondence with the client.
Tell me how to implement in C # and if there is such an opportunity.
public class _MailSender { /// <summary> /// Вложения, по умолчанию null /// </summary> public List<Attachment> Attachments = new List<Attachment>(); /// <summary> /// Содержимое письма, по умолчанию пустое /// </summary> public string Body = string.Empty; /// <summary> /// Отправитель, по умолчанию значение берется из конфига /// </summary> public string EmailFrom = ConfigurationManager.AppSettings["Mailsender_email_from"]; /// <summary> /// Адресат(ы), указываются через ',' или ';', по умолчанию значение пустое /// </summary> public string EmailTo = string.Empty; /// <summary> /// Является ли содержимое письма HTML, по умолчанию true /// </summary> public bool IsBodyHtml = true; /// <summary> /// Использовать ли защищенный протокол SSL, по умолчанию false /// </summary> public bool SMTPEnableSsl = _Data.GetBool(ConfigurationManager.AppSettings["Mailsender_smtp_use_ssl"]); /// <summary> /// SMTP Логин, по умолчанию значение берется из конфига. Если не указан логин или пароль /// SmtpServer.Credentials установлен не будет /// </summary> public string SMTPLogin = ConfigurationManager.AppSettings["Mailsender_smtp_login"]; /// <summary> /// SMTP Пароль, по умолчанию значение берется из конфига. Если не указан логин или пароль /// SmtpServer.Credentials установлен не будет /// </summary> public string SMTPPassword = ConfigurationManager.AppSettings["Mailsender_smtp_password"]; /// <summary> /// SMTP Порт, по умолчанию 25 /// </summary> public int SMTPPort = _Data.GetInt(ConfigurationManager.AppSettings["Mailsender_smtp_port"]); /// <summary> /// SMTP Сервер, по умолчанию значение берется из конфига /// </summary> public string SMTPServer = ConfigurationManager.AppSettings["Mailsender_smtp_server"]; /// <summary> /// Тема письма /// </summary> public string Subject = string.Empty; /// <summary> /// Ссылка для отписки /// </summary> public string ListUnsubscribe = string.Empty; /// <summary> /// Делегат для ассинхронной отправки писем /// </summary> /// <param name="mailMessage"></param> private delegate void SomeDelegate(MailMessage mailMessage); /// <summary> /// Отправляет сообщение с настройками заданными в этом классе /// </summary> public void MailSend() { // Обработка ошибок входящих параметров if (string.IsNullOrEmpty(this.SMTPServer)) throw new Exception("Нет настроек почты. Сообщение не отправлено"); if (string.IsNullOrEmpty(this.EmailTo)) throw new Exception("Не указаны получатели. Сообщение не отправлено"); if (string.IsNullOrEmpty(this.EmailFrom)) throw new Exception("Не указан электронный адрес отправителя. Сообщение не отправлено"); // Меняем разделитель, на тот, который поддерживает MailMessage EmailTo = EmailTo.Replace(";", ","); MailMessage mailMessage = null; // Формирование сообщения try { mailMessage = new MailMessage(new MailAddress(this.EmailFrom), new MailAddress(this.EmailTo)); } catch (Exception ex) { throw new Exception(ex.Message); } // Отправитель и получатель (проверка на валидность адресов) try { mailMessage.From = new MailAddress(this.EmailFrom); } catch (FormatException) { throw new Exception("Электронный адрес отправителя не соответствует формату. Сообщение не отправлено"); } try { mailMessage.To.Add(this.EmailTo); } catch (FormatException) { throw new Exception("Электронный адрес получателя(ей) не соответствует формату. Сообщение не отправлено"); } if (_Data.GetString(ListUnsubscribe) != "") { mailMessage.Headers.Add("List-Unsubscribe", ListUnsubscribe); } mailMessage.Subject = this.Subject; mailMessage.Body = this.Body; mailMessage.IsBodyHtml = this.IsBodyHtml; foreach (Attachment a in this.Attachments) mailMessage.Attachments.Add(a); // Формирование смтпКлиента SmtpClient client = new SmtpClient(this.SMTPServer); client.Port = this.SMTPPort; if (!string.IsNullOrEmpty(this.SMTPLogin) && !string.IsNullOrEmpty(this.SMTPPassword)) client.Credentials = new System.Net.NetworkCredential(this.SMTPLogin, this.SMTPPassword); client.EnableSsl = this.SMTPEnableSsl; //client.Send(mailMessage); try { client.Send(mailMessage); } catch (Exception ex) { } } }
Reply-To:
header for the answer, and if you add an email other than the email account from which the letter leaves From, such a letter will fall into spam. - VismanmailMessage.ReplyToList.Add("email@example.com");
- Oxot_nik