Please check Below Code for your reference. We sets display name for sender from where we sends an email.
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.SendEmail("fromemail@email.com", "Email Subject", "Your Email Body", "Your Display Name");
}
}
public void SendEmail(string fromEmailAddress, string subject, string body, string displayName)
{
using (MailMessage mm = new MailMessage())
{
// To set Email Id Which user has entered also if Display name is there the pass it as second parameter when assigning mm.From in new MailAddress.
// You can set sender's display name
mm.From = new MailAddress(fromEmailAddress, displayName);
// It is receiver email Id which we assign in mm.To.
mm.To.Add(new MailAddress("Youremail@gmail.com"));
// Subject which you sets from Email
mm.Subject = subject;
// Body which Sets for Email
mm.Body = body;
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
// Your Account details which you are going to Send Email from Application
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
System.Net.NetworkCredential networkCred = new System.Net.NetworkCredential();
networkCred.UserName = fromEmailAddress;
networkCred.Password = "your gmail password";
smtp.UseDefaultCredentials = true;
smtp.Credentials = networkCred;
smtp.Port = 587;
smtp.Send(mm);
}
}