24

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

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
MeqDotNet
  • 718
  • 2
  • 8
  • 24

4 Answers4

46

Like this:

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

    new SmtpClient().Send(message);
}

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

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
10

you could try something like this

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

More info here

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

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
Bala R
  • 107,317
  • 23
  • 199
  • 210
6

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

James
  • 80,725
  • 18
  • 167
  • 237
2

This is how it works.

MailMessage message;
//prepare message
message.Sender = new MailAddress("Sender-email-id", "Sender Name");
new SmtpClient().Send(message); 
this. __curious_geek
  • 42,787
  • 22
  • 113
  • 137