Hi,
I am making a form in asp.net 3.5 which will send an email to the recipient
Initially I was using system.web.mail
as it is obvious whenever you send an email to some recipient a display name appears instead
of theemail id of the sender
consider:
[email protected]
display_name="my name"
in my case instead of the display_name "mail" the initial portion of the sender's email id is coming
but it is desired that "my name" should appear in the recipient's inbox.
due to this I had to switch to system.net.mail
but there also same problem occurs.
I have tried googling on this issue too, but still no help.
Any help shall be appreciated !
Thanks
Pankaj
Loading

Kirtan PatelRank #292 · 8.6K reputationPosted Oct 23, 2009, 7:50 AM EDT
using System.Text;
Venkatesh Ellur30 reputationPosted Oct 23, 2009, 3:53 AM EDT
Pankaj Singh92 reputationPosted Oct 23, 2009, 4:02 AM EDT
My code:
- try
- {
- //Creating new mail message
- System.Web.Mail.MailMessage MyMail = new System.Web.Mail.MailMessage();
-
- //Display Name can be sent using following format
- //\<
>\ " - MyMail.From = @"\Webtips Emailer\
" ; -
- //To Address
- MyMail.To = "[email protected]";
-
- // BCC Address
- MyMail.Bcc = "[email protected]";
-
- //Mail Subject
- MyMail.Subject = "Subject Of the mail";
-
- //Body of the mail
- MyMail.Body = "test mail message";
- MyMail.BodyFormat = System.Web.Mail.MailFormat.Html;
-
- //SMTP Server name or IP from which mail to be sent
- System.Web.Mail.SmtpMail.SmtpServer = "smtp.someserver.com";
-
- //Sending Mail
- System.Web.Mail.SmtpMail.Send(MyMail);
- }
- catch
- {
- }
PankajKirtan PatelRank #292 · 8.6K reputationPosted Oct 23, 2009, 4:52 AM EDT
protected void btnSend_Click(object sender, EventArgs e) { SmtpClient client = new SmtpClient(); MailMessage message = new MailMessage(); client.Port = 587; client.Host = "smtp.gmail.com"; client.UseDefaultCredentials = true; client.Credentials = new System.Net.NetworkCredential(txtemail.Text ,txtpass.Text ); client.EnableSsl = true; try { MailAddress SendTo = new MailAddress(txtTo.Text); MailAddress SendFrom = new MailAddress(txtFrom.Text); message = new MailMessage(SendFrom, SendTo); message.Body = txtMessage.Text; message.Subject = txtSub.Text; client.Send(message); txtStatus.Text = "Your email has been sent"; Page.RegisterClientScriptBlock("Thanks!", "alert('Thanks! for using this tool.')"); } catch (Exception ex) { txtStatus.Text = ex.ToString(); } } }Pankaj Singh92 reputationPosted Oct 23, 2009, 6:22 AM EDT
In your code there is no code to display name, when we sending mail.
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 23, 2009, 6:57 AM EDT
check "Do you like this answer" if it helped you :) protected void Button1_Click(object sender, EventArgs e) { SmtpClient client = new SmtpClient(); MailMessage message = new MailMessage(); client.Port = 587; client.Host = "smtp.gmail.com"; client.UseDefaultCredentials = true; client.Credentials = new System.Net.NetworkCredential("[email protected]", "mygmailpassword"); client.EnableSsl = true; try { MailAddress SendTo = new MailAddress("[email protected]"); MailAddress SendFrom = new MailAddress("[email protected]"); message = new MailMessage(SendFrom, SendTo); message.Body = "this is content Of Mail"; message.Subject = "Test Subject"; message.SubjectEncoding = Encoding.UTF8; //Add Mail Header message.Headers.Add("You Name", "Your Company Name"); client.Send(message); Page.RegisterClientScriptBlock("Thanks!", "alert('Thanks! for using this tool.')"); } catch { } }Pankaj Singh92 reputationPosted Oct 23, 2009, 7:26 AM EDT
This line not working::