0

Ive been building my online system and i want to add report errors area. It will show simple mail form and send mail to one specific address. I can send my email when I have the same address as receiver. But how I can send to him messages from various mails? This is my model for Email class :

 [Required, Display(Name = "Name")]
    public string FromName { get; set; }

    [Required, Display(Name = "Mail"), EmailAddress]
    public string FromMail { get; set; }

    [Required, Display(Name = "Subject")]
    public string Subject { get; set; }

    [Required]
    public string Message { get; set; }

And this is my Controller :

public ActionResult Send()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Send( NotificationFromUser user)
        {
            if (ModelState.IsValid)
            {
                MailMessage _mail = new MailMessage(user.FromMail, "specific receiver mail - admin");
                _mail.Subject = user.Subject;
                _mail.Body = user.Message;

                SmtpClient smtpClient = new SmtpClient("smtp credentials", 587);
                smtpClient.Credentials = new System.Net.NetworkCredential()
                {
                    UserName = "",
                    Password = ""
                };
                smtpClient.EnableSsl = true;
                smtpClient.Send(_mail);
                return RedirectToAction("MessageSent");
            }

            return View();
        }

Any ideas how I can modify my controller?

lysy
  • 1
  • Does this answer your question? [Sending email through Gmail SMTP server with C#](https://stackoverflow.com/questions/704636/sending-email-through-gmail-smtp-server-with-c-sharp) – Neil Jun 10 '20 at 12:09

1 Answers1

0

Email generally comes from one place, i.e. the service you are writing. You should set up an account with an email provider specific to your project. I generally start new projects by creating a new gmail account.

Neil
  • 11,059
  • 3
  • 31
  • 56
  • I have email for website. But i dont know how to send e-mails from various user mails to this specific mail. – lysy Jun 10 '20 at 12:08