Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 14th, 2007, 09:12 AM
Registered User
 
Join Date: Feb 2007
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Email through Gmail in C#

Anyone have any luck sending emails through gmail accounts in C# applications? I can't get it to work. .

Thanks in advance,

Tom.

Reply With Quote
  #2 (permalink)  
Old March 14th, 2007, 09:14 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

"I can't get it to work.." could be alot of things. What have you done/tried to use their server? I assume you have a gmail account that you are sending the email through since their SMTP server requires both authentication and SSL to send email.

What errors are you getting?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Reply With Quote
  #3 (permalink)  
Old March 14th, 2007, 09:55 AM
Registered User
 
Join Date: Feb 2007
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have this in the Form_Load method:

System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage("sender@gmail.com", "recipient@gmail.com","This is the mail subject", "Just wanted to say Hello");
MyMailMessage.IsBodyHtml = false;
System.Net.NetworkCredential mailAuthentication = new
System.Net.NetworkCredential("sender@gmail.com", "password");
System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
mailClient.EnableSsl = true;
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = mailAuthentication;
mailClient.Send(MyMailMessage);

And I'm getting the following. . . . . .

System.Net.Mail.SmtpException was unhandled
  Message="Failure sending mail."
  Source="System"
  StackTrace:
       at System.Net.Mail.SmtpClient.Send(MailMessage message)
       at EmailTest.Form1.SendMail1() in C:\Documents and Settings\tobriain\Local Settings\Application Data\Temporary Projects\EmailTest\Form1.cs:line 52
       at EmailTest.Form1.Form1_Load(Object sender, EventArgs e) in C:\Documents and Settings\tobriain\Local Settings\Application Data\Temporary Projects\EmailTest\Form1.cs:line 24
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
       at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.SafeNativeMethods.ShowWindow( HandleRef hWnd, Int32 nCmdShow)
       at System.Windows.Forms.Control.SetVisibleCore(Boolea n value)
       at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Control.set_Visible(Boolean value)
       at System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at EmailTest.Program.Main() in C:\Documents and Settings\tobriain\Local Settings\Application Data\Temporary Projects\EmailTest\Program.cs:line 17
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
       at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()


Any help would be much appreciated. Could it be the socket I'm using? Or something else like that?

Tom.

Reply With Quote
  #4 (permalink)  
Old March 14th, 2007, 09:59 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I think Gmails SMTP runs off port 425. Nevertheless, what you should do is login to your gmail account and go to the instructional page on how to setup outlook to send and recieve emails using Gmail, that will give you all of the port informaiton that you need.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Reply With Quote
  #5 (permalink)  
Old March 16th, 2007, 02:13 AM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't think, they'll allow to use their SMTP server and send mail to others. Otherwise, the millions of spam mails will be send by using their server.

Reply With Quote
  #6 (permalink)  
Old April 5th, 2007, 07:57 AM
Registered User
 
Join Date: Apr 2007
Location: Everett, WA, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I use GMail via Outlook. The SMTP port is 465 so yes, they allow you to send mail via their SMTP servers.

HOWEVER! By default, you are not allowed to send mail via SMTP. You have to go to your gmail account and edit your preferences to enable POP/SMTP access. http://mail.google.com/support/bin/a...273&topic=1556

Once enabled and you use the proper port, all should work well.

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Contact Form and Gmail Jamessaep BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 April 16th, 2008 07:58 AM
Gmail vicoldan Need help with your homework? 2 January 29th, 2008 02:24 PM
File attachment like as in gmail Sasikn75 Flash (all versions) 1 January 4th, 2007 11:39 PM
GMail Attachments prophet Javascript How-To 3 January 24th, 2006 02:03 AM
gmail to database rajuru Beginning PHP 0 July 26th, 2005 01:47 AM



All times are GMT -4. The time now is 12:42 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.