All source code in .Net Ask a .Net Pro Discussion Forum Categories All jobs in .Net
SSL,Connects,smtpgmailcom,authenticate,valid,
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
.Net Stats

 Code: 655,633. lines
 Jobs: 796. postings

 How to support the site

 
Sponsored by:
Quick Search for:  in language:    
You are in:
 
Login





Latest postings for .Net.
Click here to see a screenshot of this code!TeamVision Revisted 3.0
By ArkitechEBC on 11/16

(Screen Shot)

Click here to see a screenshot of this code!Simplest Explorer Treeview
By M1K3 on 11/16

(Screen Shot)

Click here to see a screenshot of this code!Lite Brite Application
By Brian McCumber on 11/11

(Screen Shot)

Click here to see a screenshot of this code!CAR DEALER/ CAR SALE
By YESSOUFOU ABDEL RAOUF on 11/10

(Screen Shot)

Click here to see a screenshot of this code!CPU usage tester / benchmark
By Timo Boehme on 11/16

(Screen Shot)

Arrays functions
By Jerome Scott II on 11/15


C# regex example
By Jerome Scott II on 11/15


Click here to put this ticker on your site!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!



 
 
   

Send mail with SmtpClient using Gmail SMTP Server

Print
Email
 
VB icon
Submitted on: 5/10/2006 1:52:04 AM
By: Bernardo Bicalho  
Level: Intermediate
User Rating: By 1 Users
Compatibility:C#

Users have accessed this code 15923 times.
 
author picture
(About the author)
 
     Connects to smtp.gmail.com, authenticate a valid gmail user account using SSL and sends an email. Regular SSL port 465 won´t work. You´ll have to use an alternate port, 587.
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!

    //**************************************
    //     
    // for :Send mail with SmtpClient using 
    //     Gmail SMTP Server
    //**************************************
    //     
    You are using Gmail services. Read their license of agreement to make sure you won´t do anything they wouldn´t aprove.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    //**************************************
    //     
    // Name: Send mail with SmtpClient using
    //     Gmail SMTP Server
    // Description:Connects to smtp.gmail.co
    //     m, authenticate a valid gmail user accou
    //     nt using SSL and sends an email.
    Regular SSL port 465 won´t work. You´ll have to use an alternate port, 587.
    // By: Bernardo Bicalho
    //
    // Inputs:valid gmail user account
    valid gmail user password
    //
    //This code is copyrighted and has    // limited warranties.Please see http://
    //     www.Planet-Source-Code.com/vb/scripts/Sh
    //     owCode.asp?txtCodeId=4733&lngWId=10    //for details.    //**************************************
    //     
    
    MailMessage MailObj = new MailMessage();
    				MailObj.To.Add("to@to.com");
    				//MailObj.From = "GmailAccount@gmail.com";
    				MailObj.From = new MailAddress("GmailAccount@gmail.com","From");
    				//MailObj.Cc = "cc@cc.com";
    			
    MailObj.IsBodyHtml = true;
    	
    				MailObj.Priority = MailPriority.Normal ;
    			string sAttach = @"c:\yourpic.jpg";
    MailObj.Attachments.Add(new Attachment(sAttach));
    				MailObj.Subject = "Subject";
    				MailObj.Body = "<table><tr><td>Test</td></tr></table>";
    SmtpClient smtpcli = new SmtpClient("smtp.gmail.com", 587); //use this PORT!
    smtpcli.EnableSsl = true;
    smtpcli.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtpcli.Credentials = new NetworkCredential("GmailAccount@gmail.com", "GmailAccountPassword");
    try
    {
    smtpcli.Send(MailObj);
    }
    catch (Exception ex)
    {
    throw new Exception(ex);}


Other 1 submission(s) by this author

 

 
 Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:
 
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
4/3/2007 3:24:36 AMCodeBased

Hi there...


Thank you for sharing about SmtpClient class.

I need to know if you know how to connect with the gmail through socket programming so that I can run RAW commands on their pop server?

Kind regards,
Amit
(If this comment was disrespectful, please report it.)

 
4/3/2007 7:59:41 AMJason Vetter

Hey Amit, Googles Pop3 server is no different from any other pop server. There are lots of POP3 client examples on this site.
(If this comment was disrespectful, please report it.)

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
To post feedback, first please login.


 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Games | Feedback | Customize | .Net Home | Site Home | Other Sites | Open Letter from Moderators | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997-2009 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.   Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.