| Home >
Code Samples >
Java >
Send email using Gmail Mail Server
|
  |
Send email using Gmail Mail Server
| Description: |
This is very good example ..just copy and paste and just change username and password in sendMail function call ... Add as much of to ,cc, bcc addresses.. Try now |
| Date added: |
06 November, 2006 |
| Submitted By: |
iamdvr |
| Rating: |
9 |
| Download: |
N/A |
| Instructions: |
set CLASSPATH=%CLASSPATH%;activation.jar;mail.jar javac Mail.java java Mail |
| Source Code: |
|
|
|
|
|
| Posted by Gopal at 12 July, 2007 |
| Brilliantly coded, Thanks ! . But I'm still getting exception: "Could not connect to SMTP host: smtp.gmail.com, port: 25;" |
|
| Posted by Ejaz Azeem at 24 August, 2007 |
I have run this code without error, If you can post full exception trace here, I may help then.
Regards.
|
|
| Posted by Ashraf at 01 October, 2007 |
| Excellent. works great, Thanks! |
|
| Posted by ashwin at 19 November, 2007 |
Hi dude, thanks for sending..........
|
|
| Posted by rahul at 06 December, 2007 |
Here is the stacktrace of the error i'm getting...
C:javamail>javac Mail.java
C:javamail>java Mail DEBUG: setDebug: JavaMail version 1.4.1 DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.s mtp.SMTPTransport,Sun Microsystems, Inc] DEBUG SMTP: useEhlo true, useAuth true DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, p ort: 465; nested exception is: java.net.ConnectException: Connection timed out: connect at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:41 2) at javax.mail.Service.connect(Service.java:288) at javax.mail.Service.connect(Service.java:169) at Mail.sendMail(Mail.java:72) at Mail.main(Mail.java:20) Caused by: java.net.ConnectException: Connection timed out: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(Unknown Source) at java.net.PlainSocketImpl.connectToAddress(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(Unknown Source) at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(Unknown Source ) at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:233) at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:163) at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1359) ... 5 more
Please help back to rectify the error |
|
|
|
|
| No tips added yet. Be the first one to share tip. |
|
| Posted by Newb at 01 March, 2008 |
| First piece of code that actually works out of the box. - Great Job |
|
Tags
|
|
Technology, Source Code, Java
|
Related Items
|
| Simple Calculator |
| Function pointers and Function returning pointers |
| XML CODE |
| Customer List With Edit and Delete Options |
| Random Password Generation function |
Related Categories
|
| Projects » JAVA |
| Web Design » Java Script |
| DB2 » Database » Java |
| Oracle » Database » Java |
| Code Samples » Java |
|