954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Email Sender Code, What wrong??

I Could not understand what is happening on my code. When i try to send an email to another email address it keeps on sending on my gmail account.
eg.
From:xxx@gmail.com
to: [email]yyy@yahoo.com[/email]

The email which supposed to be sent on [email]yyy@yahoo.com[/email], instead it send to [email]xxx@gmail.com[/email].
here is my code. I used gmail server on this.

private void btnSend_Click(object sender, EventArgs e)
{
try
{

MailMessage mail=new MailMessage();
MailAddress myAddress = new MailAddress(txtFrom.Text);
MailAddress myReceipient = new MailAddress(txtTo.Text);

mail.From = myAddress;
mail.To.Add(myReceipient.Address);

mail.Subject = txtSubject.Text;
mail.Body = txtBody.Text;

client.Host = "smtp.gmail.com";
client.Port = 587;

client.Credentials = new NetworkCredential("xxx@gmail.com","<somepassword>");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;

client.Send(mail);
MessageBox.Show("Message Sent");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

gennesis
Newbie Poster
14 posts since Jan 2012
Reputation Points: 8
Solved Threads: 0
 

Is the email you are sending from a valid address for that domain? If not then gmail is probably not sending using that address as it doesn't comply with the security credentials you supplied.

hericles
Practically a Posting Shark
823 posts since Nov 2007
Reputation Points: 136
Solved Threads: 167
 
Is the email you are sending from a valid address for that domain? If not then gmail is probably not sending using that address as it doesn't comply with the security credentials you supplied.


yes.. it is a valid email address, perhaps the things that i dont understand is the first time i run it work perfectly but the moment when i re run again, their the problem starts. so i need to close again me work, open again. i do not know if their is a sort of refresh method that refresh the smpt server??

gennesis
Newbie Poster
14 posts since Jan 2012
Reputation Points: 8
Solved Threads: 0
 

Are you manually logging in to your gmail account between runs of the program?
If so, you could be creating a cache of your credentials that the server is using by default.

Do you have a yahoo account? Can you use the yahoo server to send mail instead of the gmail server?

thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

Are you manually logging in to your gmail account between runs of the program? If so, you could be creating a cache of your credentials that the server is using by default.

Do you have a yahoo account? Can you use the yahoo server to send mail instead of the gmail server?

Thanks you all. I have already solve the problem. I just found out that one of my variable is affecting the the text that had been displayed on my txtTo Textbox. Fool of me i did not see it right away. but any way the code is working it might help on others. Thanks.....

gennesis
Newbie Poster
14 posts since Jan 2012
Reputation Points: 8
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You