Sending emails in asp.net with specific name instead of sender email

梦想的初衷 提交于 2019-12-03 06:44:35

问题


I need to send an email in asp.net but I need sender appears like "MySiteName" without info@mysitename.com.


回答1:


Like this:

using(MailMessage message = new MailMessage(
        new MailAddress("You@Domain.com", "Your Name"),
        new MailAddress("Recipient@OtherDomain.com", "Their Name")
    )) {
    message.Subject = ...;
    message.Body = ...;

    new SmtpClient().Send(message);
}

You will need to enter the SmtpClient's connection settings in Web.config




回答2:


you could try something like this

MailAddress from = new MailAddress("info@mysitename.com", "MySiteName");

More info here

http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.aspx




回答3:


There are 2 ways, if you are using MailAddress you can use the constructor overload to input the display name, or simply format the recipient address as MySiteName <info@mysitename>

For a downloadable example see here




回答4:


This is how it works.

MailMessage message;
//prepare message
message.Sender = new MailAddress("Sender-email-id", "Sender Name");
new SmtpClient().Send(message); 


来源:https://stackoverflow.com/questions/2737699/sending-emails-in-asp-net-with-specific-name-instead-of-sender-email

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!