Click here to Skip to main content
15,914,163 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to put Firstname and Lastname in place of email address while sending mail in asp.net using c# ?
Like " From : Nilesh Deokar " in place of " From : nileshdeokar@gmail.com "
Posted
Updated 23-May-12 2:15am
v2
Comments
Ganesan Senthilvel 23-May-12 10:19am    
Hope you got enough answers.

Hi ,
Check this link
sending emails in asp.net[^]
Best Regards
M.Mitwalli
 
Share this answer
 
Try the following:

Create an instance of MailAddress class that will be assigned to To property. Then assign to it the DisplayName property.

Example:
C#
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();

MailAddress from = new MailAddress("ben@contoso.com", "Ben Miller");
from.DisplayName = "My name";
message.From = from;

// Send SMTP mail
smtpClient.Send(message);


You can also find more info here:
http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.aspx[^]


Cheers
 
Share this answer
 
You can use the DisplayName property of the EmailAddress class or provide the display name in the constructor.

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

C#
MailAddress from = new MailAddress"ben@contoso.com", "Ben Miller");
MailAddress to = new MailAddress("jane@contoso.com", "Jane Clayton");
MailMessage message = new MailMessage(from, to);
message.Subject = "Using the SmtpClient class.";
message.Body = @"This is the body of this email.";

SmtpClient client = new SmtpClient(serveraddress);

try
{
  client.Send(message);
}
catch (Exception ex)
{
  Console.WriteLine(ex.ToString());
}


Regards,
Gerald
 
Share this answer
 
Hi,

Use this constructor of MailAddress:

C#
msg.From = new MailAddress("sunnykumar.xyz@abc.com", "Sunny Kumar Test Account");


Hope this help you !!

Happy Coding :)
 
Share this answer
 
v2
Hey,

Check out this blog post. It explains sending mails from C#/ASP.NET
http://www.darshansblog.com/send-email-gmail-c/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900