使用SMTP发送来自别名地址的电子邮件
问题描述:
这个问题已经被问过很多次了,但我仍然在努力寻找一个可行的解决方案。使用SMTP发送来自别名地址的电子邮件
请考虑下面的代码:
SmtpClient mailClient = new SmtpClient("outlook.office365.com");
MailMessage msgMail = new MailMessage();
msgMail.From = new MailAddress("[email protected]", "[email protected]");
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = new NetworkCredential("[email protected]", "password");
mailClient.EnableSsl = true;
MailAddress sendMailTo = new MailAddress("[email protected]", "Mark Twain")
msgMail.To.Add(sendMailTo);
msgMail.Subject = "Test Subject";
msgMail.Body = "Email content";
msgMail.IsBodyHtml = true;
mailClient.Send(msgMail);
msgMail.Dispose();
当someValidUser
- 收件人 - 接收电子邮件,我想让它显示的显示名称:[email protected]
,而不是注册到[email protected]
帐户的用户名。
我该如何做到这一点?
试过了。没有帮助.. –
这可能与您的问题有关吗? https://stackoverflow.com/questions/6209163/send-an-email-using-smtp-and-control-sender-address?rq=1 –
是的,这正是我想实现的,但我没有使用Gmail,但Outlook的SMTP服务器..同样适用? –