 |
| ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 25th, 2009, 03:58 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
|
|
Email question...
hi all, long time no see.
im making a website and cant get the email to send from my site to my dads email.
using System.Net.Mail
Code:
protectedvoid btnSend_Click(object sender, EventArgs e)
{
string Email, Name, Message, Subject;
Email = tbEmail.Text;
Name = tbContact.Text;
Message = tbMessage.Text;
Subject = Name + " has contacted you via AltaLomaTax.com!";
string message = Name + "(" + Email + ") " + "has sent the following message to you:\n" + Message;
SmtpClient mailClient = newSmtpClient();
mailClient.EnableSsl = true;
mailClient.Send(myemail, hisemail, Subject, message);
}
|
|

August 25th, 2009, 03:59 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
|
|
the following doesnt generate any errors, but i notice that the email doesnt end up in anyone's inbox.
|
|

August 25th, 2009, 04:04 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
>> mailClient.Send(myemail, hisemail, Subject, message);
You're never assigning a value to variables like myemail and hisemail......
Imar
|
|

August 26th, 2009, 12:42 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
|
|
sorry i should have mentioned that... when i copy+pasted the code here i had string literals (the one sending was my gmail and the one recieving was my yahoo)
|
|

August 26th, 2009, 04:18 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Maybe the mail ends up in the junk folder?
Cheers,
Imar
|
|

August 26th, 2009, 08:28 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
Or you have not set up the SMTP properly?
__________________
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the proof.
================================================== =========
|
|

August 28th, 2009, 10:31 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
|
|
hello guys, sorry it took so long to get back on
the email didnt show up in the junk folder and i checked the smtp info from google.com
also, i have revised the code a little bit more. here is what i have now:
Code:
MailMessage mailObj = newMailMessage();
mailObj.Body = message;
mailObj.IsBodyHtml = true;
mailObj.Subject = Subject;
mailObj.To.Add("i put my yahoo adress here");
mailObj.To.Add("this is my hotmail adress");
mailObj.To.Add("sending it to my gmail");
mailObj.From = newMailAddress("i put my gmail adress here");
SmtpClient mailClient = newSmtpClient("smtp.gmail.com");
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = new System.Net.NetworkCredential("mygmailemail", "mypassword");
mailClient.EnableSsl = true;
mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mailClient.Port = 465; // can be one of two values
mailClient.Send(mailObj);
|
|

August 29th, 2009, 03:45 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Your code looks fine. I just copied and pasted in one of my projects and I could send e-mail using GMail's SMTP server. So, it must be something else.
Have you tried port 587 instead of 465? Or maybe something on your network is blocking your e-mail? E.g. a firewall?
Otherwise, I don't know what to suggest. This is valid code...
Cheers,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

August 29th, 2009, 09:43 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
|
|
i tried both ports, i even added them to my firewall. i guess i'll just have to wait till i get these on a server.
|
|

August 29th, 2009, 09:44 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
|
|
thanks again Imar
|
|
 |