I have added code which will send emails to the receiving party. As of now I need to add the same email address in "from" email and "username"(config email) to send the email else it will fail. But I wish to have different "from" email and not asking users for password and using one config mail to send email so multiple users can consume this service to send emails. Is it possible to do so?
Here is my code:
public async Task<string> Send(string from, string to, string subject, string html, string userName, string password)
{
// create message
var email = new MimeMessage();
email.From.Add(MailboxAddress.Parse(from));
email.To.Add(MailboxAddress.Parse(to));
email.Subject = subject;
email.Body = new TextPart(TextFormat.Html) { Text = html };
using var smtp = new SmtpClient();
smtp.Connect("smtp.live.com", 587, SecureSocketOptions.StartTls);
smtp.Authenticate(userName, password);
smtp.Send(email);
smtp.Disconnect(true);
return "Email Set";
}
question from:
https://stackoverflow.com/questions/65650378/is-it-possible-to-have-a-different-sender-email-and-configuration-email-to-send 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…