email using asp.net..email comes back in my source address.. [Resolved]

Posted by sourabhghosh49-13964 under ASP.NET on 3/6/2012 | Points: 10 | Views : 1829 | Status : [Member] | Replies : 13
when i am trying to send email it comes in the source address(bob_babab2005@yahoo.com).i am trying to send mail to others using my yahoo account.
i want to send email to others like abc@gmail.com
how to do this.....

code given bellow----

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
//using System.Web.Mail;
using System.Net.Mail;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
SmtpClient client = new SmtpClient("smtp.mail.yahoo.com", 587);
MailMessage mail_msg = new MailMessage();

MailAddress fromAdd = new MailAddress(txtFrom.Text.Trim(), txtName.Text.Trim());
mail_msg.From = fromAdd;
mail_msg.To.Add("bob_babab2005@yahoo.com");
mail_msg.Subject = "Contact Me";
mail_msg.IsBodyHtml = true;
mail_msg.Body = "Message From: " + txtFrom.Text.Trim() + "Subject:" + txtCc.Text.Trim()+ "Email: " + txtTo.Text.Trim() + "Comment: " + txtComments.Text.Trim();

System.Net.NetworkCredential basicCredential = new System.Net.NetworkCredential("bob_babab2005@yahoo.com", "*********");
//client.EnableSsl = true;
client.UseDefaultCredentials = true;
client.Credentials = basicCredential;
client.Send(mail_msg);

}
}

sourabh


Responses

Posted by: Hmanjarawala on: 3/6/2012 [Member] Bronze | Points: 50

Up
0
Down

Resolved
Hi try this code, i test this code, its working

SmtpClient client = new SmtpClient("smtp.mail.yahoo.com", 25);
MailMessage mail_msg = new MailMessage();

MailAddress fromAdd = new MailAddress(tbFrom.Text.Trim()); //hmanjarawala@yahoo.com
mail_msg.From = fromAdd;
mail_msg.To.Add(new MailAddress(tbTo.Text.Trim())); //hmanjarawala@gmail.com
mail_msg.Subject = tbSubject.Text;
mail_msg.IsBodyHtml = true;
mail_msg.Body = "Message From: " + tbFrom.Text.Trim() + "Subject:" + tbSubject.Text.Trim() + "Email: " + tbTo.Text.Trim() + "Content: " + tbContent.Text.Trim();

System.Net.NetworkCredential basicCredential = new System.Net.NetworkCredential("hmanjarawala@yahoo.com", "***********");
client.EnableSsl = false;
client.UseDefaultCredentials = true;
client.Credentials = basicCredential;
client.Send(mail_msg);


Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

sourabhghosh49-13964, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 3/6/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi saurabh, plz verify your code....
you have given your address in "To" section....
mail_msg.To.Add("bob_babab2005@yahoo.com"); 

give others address rather then yours.


Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

sourabhghosh49-13964, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: sourabhghosh49-13964 on: 3/6/2012 [Member] Starter | Points: 25

Up
0
Down
hi himanshu...
if i cahnge mail_msg.To.Add("bob_babab2005@yahoo.com") tomail_msg.To.Add("abc@gmail.com")

it gives error...

i want to send email to abc@gmail.com using my yahoo account that is bob_babab2005@yahoo.com

what will be the code....plz help..
and thanks for instant reply

sourabh

sourabhghosh49-13964, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: sourabhghosh49-13964 on: 3/6/2012 [Member] Starter | Points: 25

Up
0
Down
SmtpClient client = new SmtpClient("smtp.mail.yahoo.com", 25);
MailMessage mail_msg = new MailMessage();

MailAddress fromAdd = new MailAddress(txtFrom.Text.Trim(), txtName.Text.Trim());
mail_msg.From = fromAdd;
mail_msg.To.Add(txtTo.Text.Trim());
mail_msg.Subject = "Contact Me";
mail_msg.IsBodyHtml = true;
mail_msg.Body = "Message From: " + txtFrom.Text.Trim() + "Subject:" + txtCc.Text.Trim()+ "Email: " + txtTo.Text.Trim() + "Comment: " + txtComments.Text.Trim();


i did this....but email did not come to abc@gmail.com
abc@gmail.com comes from 'txtTo' text box

sourabh

sourabhghosh49-13964, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 3/6/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi sourabh,
as per my knowledge..you can't send mail to address, which is not available

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

sourabhghosh49-13964, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: sourabhghosh49-13964 on: 3/6/2012 [Member] Starter | Points: 25

Up
0
Down
it is example only....
i am trying to send email in valid accounts using bob_babab2005@yahoo.com,it is also a valid account...

sourabh

sourabhghosh49-13964, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 3/6/2012 [Member] Bronze | Points: 25

Up
0
Down
ok then set EnableSSL true and remove credential you set

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

sourabhghosh49-13964, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: sourabhghosh49-13964 on: 3/6/2012 [Member] Starter | Points: 25

Up
0
Down
Server does not support secure connections.

this error message coming...:(

sourabh

sourabhghosh49-13964, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 3/6/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi,
Set EnableSSL true and port no. 587 instead of 25

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

sourabhghosh49-13964, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: sourabhghosh49-13964 on: 3/6/2012 [Member] Starter | Points: 25

Up
0
Down
final code is here

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
//using System.Web.Mail;
using System.Net.Mail;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
SmtpClient client = new SmtpClient("smtp.mail.yahoo.com", 587);
MailMessage mail_msg = new MailMessage();

MailAddress fromAdd = new MailAddress(txtFrom.Text, txtName.Text);
mail_msg.From = fromAdd;
mail_msg.To.Add("sourabh.ghosh49@gmail.com");
mail_msg.Subject = "Contact Me";
mail_msg.IsBodyHtml = true;
mail_msg.Body = "Message From: " + txtFrom.Text.Trim() + "Subject:" + txtCc.Text.Trim()+ "Email: " + txtTo.Text.Trim() + "Comment: " + txtComments.Text.Trim();

System.Net.NetworkCredential basicCredential = new System.Net.NetworkCredential("bob_babab2005@yahoo.com", "######");
client.EnableSsl = true;
//client.UseDefaultCredentials = true;
client.Credentials = basicCredential;
client.Send(mail_msg);

}
}

but stiil said....


Server does not support secure connections.


i think yahoo does support ssl....


sourabh

sourabhghosh49-13964, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: sourabhghosh49-13964 on: 3/6/2012 [Member] Starter | Points: 25

Up
0
Down
ok....it's solved....
i am just trying to send a mail on gmail account through yahoo.which is not supported because gmail is ssl enabled site....ok
thanks for reply

sourabh

sourabhghosh49-13964, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: sourabhghosh49-13964 on: 3/6/2012 [Member] Starter | Points: 25

Up
0
Down
thank you so much ...now i can also able to send email in gmail account using yahoo account....
thank you...it works..

sourabh

sourabhghosh49-13964, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 3/6/2012 [Member] Bronze | Points: 25

Up
0
Down
Mark this as Answer, if it solve your problem

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

sourabhghosh49-13964, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response