Wrox Programmer Forums
|
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
 
Old August 25th, 2009, 03:58 PM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default 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);
}
 
Old August 25th, 2009, 03:59 PM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default

the following doesnt generate any errors, but i notice that the email doesnt end up in anyone's inbox.
 
Old August 25th, 2009, 04:04 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

>> mailClient.Send(myemail, hisemail, Subject, message);

You're never assigning a value to variables like myemail and hisemail......

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 26th, 2009, 12:42 AM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default

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)
 
Old August 26th, 2009, 04:18 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Maybe the mail ends up in the junk folder?

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 26th, 2009, 08:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

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.
================================================== =========
 
Old August 28th, 2009, 10:31 PM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default

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);
 
Old August 29th, 2009, 03:45 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
iceman90289 (August 29th, 2009)
 
Old August 29th, 2009, 09:43 AM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default

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.
 
Old August 29th, 2009, 09:44 AM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default

thanks again Imar





Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic CDOSYS email form question ottostudios Classic ASP Professional 1 August 14th, 2009 05:18 AM
SMTP Email question snufse ASP.NET 2.0 Basics 2 July 9th, 2009 11:08 AM
Ch. 11 Email setup question amenne20 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 October 1st, 2006 04:04 PM
Ch. 11 Email setup question amenne20 BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 October 1st, 2006 04:03 PM
Email Form - Question from a Newbie morgan270 ASP.NET 2.0 Basics 8 September 13th, 2006 03:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.