7
Answers

problem with SendingMail

Photo of Pankaj Singh

Pankaj Singh

15y
2.6k
1
 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:

mail_sender=mail@gmail.com

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

Answers (7)

0
Photo of Kirtan Patel
NA 35k 2.8m 15y
you need to add Name Space

using System.Text;
Accepted
0
Photo of Pankaj Singh
NA 69 0 15y
Hi,

This line not working::
message.SubjectEncoding = Encoding.UTF8;
0
Photo of Kirtan Patel
NA 35k 2.8m 15y
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("kirtan007@gmail.com", "mygmailpassword");
client.EnableSsl = true;
try
{
MailAddress SendTo = new MailAddress("kirtan007@gmail.com");

MailAddress SendFrom = new MailAddress("Test@gmail.com");
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!", "<script>alert('Thanks! for using this tool.')</script>");
}
catch
{

}
}
0
Photo of Pankaj Singh
NA 69 0 15y
Hi,

In your code there is no code to display name, when we sending mail.
0
Photo of Kirtan Patel
NA 35k 2.8m 15y
Here is Better Code to Send mail using ASp.net

 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!", "<script>alert('Thanks! for using this tool.')</script>");
}
catch (Exception ex)
{
txtStatus.Text = ex.ToString();
}
}
}
check "Do you like this answer" if it helped you :)







0
Photo of Pankaj Singh
NA 69 0 15y
hi,

My code:

  1. try  
  2. {  
  3.     //Creating new mail message  
  4.     System.Web.Mail.MailMessage MyMail = new System.Web.Mail.MailMessage();  
  5.   
  6.     //Display Name can be sent using following format  
  7.     //\<<Friendly Display Name>>\ <mailaddress>"  
  8.     MyMail.From = @"\Webtips Emailer\ <admin@webtips.co.in>";  
  9.   
  10.     //To Address  
  11.     MyMail.To = "webtips.co.in@gmail.com";  
  12.   
  13.     // BCC Address  
  14.     MyMail.Bcc = "somename@someserver.com";  
  15.   
  16.     //Mail Subject  
  17.     MyMail.Subject = "Subject Of the mail";  
  18.   
  19.     //Body of the mail  
  20.     MyMail.Body = "<html><body>test mail message</body></html>";  
  21.     MyMail.BodyFormat = System.Web.Mail.MailFormat.Html;  
  22.       
  23.     //SMTP Server name or IP from which mail to be sent  
  24.     System.Web.Mail.SmtpMail.SmtpServer = "smtp.someserver.com";  
  25.   
  26.     //Sending Mail  
  27.     System.Web.Mail.SmtpMail.Send(MyMail);  
  28. }  
  29. catch  
  30. {  

Pankaj

0
Photo of Venkatesh Ellur
NA 39 0 15y
Hey pankaj can you please post the code so that i can try helping you out.