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

十年热恋 提交于 2019-12-02 21:17:10
SLaks

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

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

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

This is how it works.

MailMessage message;
//prepare message
message.Sender = new MailAddress("Sender-email-id", "Sender Name");
new SmtpClient().Send(message); 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!