Marius Vasile

Marius Vasile

  • 589
  • 1.9k
  • 148.6k

asp.net core contact form add multiple data in message body

Mar 6 2021 3:44 PM
I am using this to send email from contact form
 
  1. var message = new MimeMessage();  
  2.             message.From.Add(new MailboxAddress(_smtpSettings.SenderName, _smtpSettings.SenderEmail));  
  3.             message.To.Add(new MailboxAddress("[email protected]"));  
  4.             message.Subject = "Contact form communication";  
  5.   
  6.             message.Body = new TextPart("html")  
  7.             {  
  8.                 Text = "test message"  
  9.             };  
  10.   
  11.             using (var client = new SmtpClient())  
  12.             {  
  13.                 await client.ConnectAsync(_smtpSettings.Server, _smtpSettings.Port, true);  
  14.   
  15.                 client.AuthenticationMechanisms.Remove("XOAUTH2");  
  16.   
  17.                 await client.AuthenticateAsync(_smtpSettings.UserName, _smtpSettings.Password);  
  18.                 await client.SendAsync(message);  
  19.                 await client.DisconnectAsync(true);  
  20.             }  
 which is working very well. But the body text I want to contain concatenated values from form
 
  1. Text = ContactForm.Name + ContactForm.Email + ContactForm.Company + ContactForm.Message  

Answers (7)