MeqDotNet
MeqDotNet

Reputation: 718

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

I need to send an email in asp.net but I need sender appears like "MySiteName" without [email protected].

Upvotes: 24

Views: 39891

Answers (4)

Bala R
Bala R

Reputation: 108937

you could try something like this

MailAddress from = new MailAddress("[email protected]", "MySiteName");

More info here

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

Upvotes: 10

SLaks
SLaks

Reputation: 887195

Like this:

using(MailMessage message = new MailMessage(
        new MailAddress("[email protected]", "Your Name"),
        new MailAddress("[email protected]", "Their Name")
    )) {
    message.Subject = ...;
    message.Body = ...;

    new SmtpClient().Send(message);
}

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

Upvotes: 46

James
James

Reputation: 82096

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

Upvotes: 6

this. __curious_geek
this. __curious_geek

Reputation: 43207

This is how it works.

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

Upvotes: 2

Related Questions