Sending emails in asp.net with specific name inste

2019-03-10 20:18发布

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

4条回答
地球回转人心会变
2楼-- · 2019-03-10 20:38

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

查看更多
Root(大扎)
3楼-- · 2019-03-10 20:40

This is how it works.

MailMessage message;
//prepare message
message.Sender = new MailAddress("Sender-email-id", "Sender Name");
new SmtpClient().Send(message); 
查看更多
Emotional °昔
4楼-- · 2019-03-10 20:58

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

查看更多
兄弟一词,经得起流年.
5楼-- · 2019-03-10 21:00

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

查看更多
登录 后发表回答