26288 total geeks with 3498 solutions
Recent challengers:
 Welcome, you are an anonymous user! [register] [login] Get a yourname@osix.net email address 

Articles

GEEK

User's box
Username:
Password:

Forgot password?
New account

Shoutbox
MaxMouse
It's Friday... That's good enough for me!
CodeX
non stop lolz here but thats soon to end thanks to uni, surely the rest of the world is going good?
stabat
how things are going guys? Here... boring...
CodeX
I must be going wrong on the password lengths then, as long as it was done on ECB
MaxMouse
lol... the key is in hex (MD5: of the string "doit" without the "'s) and is in lower case. Maybe i should have submitted this as a challenge!

Donate
Donate and help us fund new challenges
Donate!
Due Date: May 31
May Goal: $40.00
Gross: $0.00
Net Balance: $0.00
Left to go: $40.00
Contributors


News Feeds
The Register
Hey, you, dev. What
do you mean,
storage is BORING?
Curse you, old
person, for
inventing
computers!
Feds slam
hacker-friendly
backdoors in
jalopy, grub
factories
4G LTE: Good for
tweets and watching
Dr Who. Crap
at saving lives
Microsoft exposes
green users"
privates in web
quiz snafu
Woolwich beheading
sparks call to
REVIVE UK Snoopers"
Charter
Is the next-gen
console war already
One?
Internet
advertising giant
(Google) "mulls"
map app Waze gobble
Did Kim Dotcom
invent 2-factor
authentication? Er,
not exactly...
"Google IS a
capitalist
country... er,
company"
Slashdot
Twitter"s New
Money-Making Plan:
Lead Generation
Bandages That Can
Turn Off Genes
Encourages Wound
Healing
BT Runs an 800GBps
Channel On Old
Fiber
Australian Police
Move To Make 3D
Printed Guns
Illegal
Cockroaches
Evolving To Avoid
Roach Motels
Meet the 23-Ton
X-Wing, the World"s
Largest Lego Model
Android Malware
Intercepts Text
Messages, Forwards
To Criminals
Scientists Growing
New Crystals To
Make LED Lights
Better
Google Takes Street
View To the
Galapagos Islands
Bitcoin"s Success
With Investors
Alienates Earliest
Adopters
Article viewer

Sending email with Java



Written by:dimport
Published by:Nightscript
Published on:2003-06-21 07:19:46
Topic:Java
Search OSI about Java.More articles by dimport.
 viewed 196174 times send this article printer friendly

Digg this!
    Rate this article :
In this example I will be taking a quick look at Java's support for email
through the JavaMail API, and will produce a simple mail client capable
of sending email with file attachments.

Installing JavaMail
You will need the latest version of JavaMail (Version 1.2) available here:

http://java.sun.com/products/javamail/

Download and unzip the file, in the newly created top level JavaMail directory you will find a number of jar files,
these need adding to your classpath.
To do this in Eclipse, right click on your project in the tree view, select properties, select the libraries tab.
Now click the 'Add external jars' button, navigate to your JavaMail directory and click on the jars.

The tutorial also makes use of the Java Activation Framework, which is available here:

http://java.sun.com/products/javabeans/glasgow/jaf.html

Instalation of JAF is identical to JavaMail

Using JavaMail
Here is the code for the mail client, it should be pretty self explanatory:


 import javax.mail.*;
 import javax.mail.internet.*;
 import javax.activation.*;
 import java.io.*;
 import java.util.Properties;
 public class MailClient
 {
 
 
     public void sendMail(String mailServer, String from, String to,
                             String subject, String messageBody,
                             String[] attachments) throws
MessagingException, AddressException
     {
         // Setup mail server
         Properties props = System.getProperties();
         props.put("mail.smtp.host", mailServer);
         
         // Get a mail session
         Session session = Session.getDefaultInstance(props, null);
         
         // Define a new mail message
         Message message = new MimeMessage(session);
         message.setFrom(new InternetAddress(from));
         message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
         message.setSubject(subject);
         
         // Create a message part to represent the body text
         BodyPart messageBodyPart = new MimeBodyPart();
         messageBodyPart.setText(messageBody);
         
         //use a MimeMultipart as we need to handle the file attachments
         Multipart multipart = new MimeMultipart();
         
         //add the message body to the mime message
         multipart.addBodyPart(messageBodyPart);
         
         // add any file attachments to the message
         addAtachments(attachments, multipart);
         
         // Put all message parts in the message
         message.setContent(multipart);
         
         // Send the message
         Transport.send(message);
 
 
     }
 
     protected void addAtachments(String[] attachments, Multipart multipart)
                     throws MessagingException, AddressException
     {
         for(int i = 0; i<= attachments.length -1; i++)
         {
             String filename = attachments[i];
             MimeBodyPart attachmentBodyPart = new MimeBodyPart();
             
             //use a JAF FileDataSource as it does MIME type detection
             DataSource source = new FileDataSource(filename);
             attachmentBodyPart.setDataHandler(new DataHandler(source));
             
             //assume that the filename you want to send is the same as the
             //actual file name - could alter this to remove the file path
             attachmentBodyPart.setFileName(filename);
             
             //add the attachment
             multipart.addBodyPart(attachmentBodyPart);
         }
     }
 
     public static void main(String[] args)
     {
         try
         {
             MailClient client = new MailClient();
             String server="pop3.mydomain.com";
             String from="myname@mydomain.com";
             String to = "someuser@somewhere.com";
             String subject="Test";
             String message="Testing";
             String[] filenames =
{"c:\somefile.txt"};
         
             client.sendMail(server,from,to,subject,message,filenames);
         }
         catch(Exception e)
         {
             e.printStackTrace(System.out);
         }
         
     }
 }
 


This article was originally written by pertinax

Did you like this article? There are hundreds more.

Comments:
nukturnal
2005-04-01 11:24:47
Yeah this code works pefectly...but u need to add a front slash infront to C:/somefile.txt for it to work.
Anonymous
2006-07-21 02:50:40
I get something like this:
javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Connection reset
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1462)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1260)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
when I run the code.What is the problem?
Anonymous
2006-09-14 12:21:20
Wow, thank you very much. This code is great. I have only problem with attachments using diacritics, for example Žlu&#357;ou&#269;ký.xls...i try to slove it...one more time thanks and sorry my bad english.
Anonymous
2007-02-11 23:44:29
hello help me guys.

javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Connection reset
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1462)
at com.sun.mail.smtp.SMTPTransport.close(SMTPTransport.java:645)
at javax.mail.Transport.send0(Transport.java:171)
at javax.mail.Transport.send(Transport.java:98)
at TestDevelop.EmailSms.send(EmailSms.java:195)
at TestDevelop.EmailSms.main(EmailSms.java:58)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:97)SMS was not sent - Exception reading response

at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:75)
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1440)
... 5 more
Anonymous
2007-06-26 06:12:49
i got a an Exception like
java.lang.NoClassDefFoundError: javax/activation/DataSource
at com.mail.MailClient.sendMail(MailClient.java:32)
at com.mail.MailClient.main(MailClient.java:72)
soloution forthsi
janus
2007-06-26 08:52:01
'these need adding to your classpath'
Anonymous
2007-07-17 02:50:54
javax.mail.MessagingException: Unknown SMTP host: pop3.yahoo.co.in;
nested exception is:
java.net.UnknownHostException: pop3.yahoo.co.in
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1280)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at MailClient.sendMail(MailClient.java:42)
at MailClient.main(MailClient.java:78)
Caused by: java.net.UnknownHostException: pop3.yahoo.co.in
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:232)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1250)
... 8 more
Anonymous
2007-08-28 18:58:38
ha guys i help me with this i got this exception

javax.mail.MessagingException: Exception reading response;
nested exception is:
javax.net.ssl.SSLException: Unsupported record version Unknown-50.49
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1462)
at com.sun.mail.smtp.SMTPTransport.close(SMTPTransport.java:645)
at javax.mail.Transport.send0(Transport.java:171)
at javax.mail.Transport.send(Transport.java:98)
at Main.<init>(Main.java:43)
at Main.main(Main.java:53)
Caused by: javax.net.ssl.SSLException: Unsupported record version Unknown-50.49
at com.sun.net.ssl.internal.ssl.InputRecord.readV3Record(Unknown Source)
at com.sun.net.ssl.internal.ssl.InputRecord.read(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.AppInputStream.read(Unknown Source)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:97)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:75)
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1440)
... 5 more

but mail is send without any problem plzz help me with this as fast u can thanxxx..
Anonymous
2007-08-31 10:17:38
at javax.activation.DataHandler.writeTo(DataHandler.java:316)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1350)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1683)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:585)
... 4 more
Anonymous
2007-10-06 13:51:41
Hey Guys , Please help me out.I got following exception


javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Connection reset
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1462)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1260)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
Anonymous
2007-10-10 07:13:33
Most of these "Exception reading response" errors are caused by the mail server rejecting the e-mail. This is usually caused by some kind of security, such as filtering based on your IP address or authentication required.
Anonymous
2008-01-29 21:31:36
This worked wonderfully for me on the first try! Thanks so much for the code. Fantastic job!
Anonymous
2008-03-09 18:33:16
hey dude...plz give me any pop3 adress of any site to work out with this code...

plz giv me procedure also..
Anonymous
2008-03-16 16:15:18
Hello,,

I want to ask about the mailServer. Should I have real one?

Or can I create one locally to use try this code?
Anonymous
2008-06-18 10:50:28
It is work successfully just one problem
it work local not work general
Anonymous
2008-08-01 04:44:10
hi
Anonymous
2008-08-01 04:45:58
hi guys i am getting errors in java mailing.
i am trying it but getting the fallowing errors can you help me out
Anonymous
2008-08-01 04:50:21
the error which i am getting is as fallows
you can mail me on jahangir.sheikh@wipro.com
javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Connection reset
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java
:1611)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1369)
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 javax.mail.Service.connect(Service.java:118)
at javax.mail.Transport.send0(Transport.java:188)
at javax.mail.Transport.send(Transport.java:118)
at SimpleSender.send(SimpleSender.java:78)
at SimpleSender.main(SimpleSender.java:28)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:110)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:88)
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java
:1589)
... 9 more

D:\Mail\com\lotontech\mail>
Anonymous
2008-08-22 07:33:23
Hi
I am getting the exception like


javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Connection reset
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1462)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1260)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at com.huawei.cct.websso.idp.authn.SendMailUsingAuthentication.sendMail(SendMailUsingAuthentication.java:113)
at com.huawei.cct.websso.idp.authn.SendMailUsingAuthentication.main(SendMailUsingAuthentication.java:48)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:97)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:75)
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1440)
... 9 more


Plz help me out i am not getting what is the problem.
Thanks
Anonymous
2008-11-17 08:45:57
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 550 <ashok.sakra@gmail.com> No such user here
can anyone tell how to solve this problem so that i can send mail.
plz provide me solution on my id - ashok.sakra@gmail.com
Anonymous
2008-11-25 07:50:55
Real a nice code wow it's work cool
to send carbon copy just add
message.addRecipient(Message.RecipientType.CC, new InternetAddress(cto));
Anonymous
2008-12-08 10:16:07
javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: 554 5.7.1 Helo invalid .

at javax.mail.Transport.send0(Transport.java:218)
at javax.mail.Transport.send(Transport.java:80)
at MailClient.sendMail(MailClient.java:45)
at MailClient.main(MailClient.java:84)
///////////
i got this error. mail me at apeksha.gholap@newgen.co.in
Anonymous
2009-02-17 10:29:28
Hello i need java prog to send mail(Smtp,pop3/imap)
Please help me.
My id krisgct@gmail.com
Anonymous
2009-02-24 06:14:01
Hello, could please tell me wat exactly is the reason for this error and wat could be done.

EXCEPTION: javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.MessagingException: 553 5.5.4 <user1>... Domain name required
Stacktrace: javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.MessagingException: 553 5.5.4 <user1>... Domain name required

at javax.mail.Transport.send0(Transport.java:218)
at javax.mail.Transport.send(Transport.java:80)
at EdisMailUtil.sendEmail(EdisMailUtil.java:202)
at EdisMailUtil.sendEmail(EdisMailUtil.java:46)
at EdisSendMail.main(EdisSendMail.java:71)
Anonymous
2009-02-26 13:06:14
xxx
Anonymous
2009-03-09 05:22:11
Simply awesome ..... gr8 work ....

Anonymous
2009-03-19 13:01:32
Hi,I am facing the same problem.
Error: Domain isn't in my list.My program is fine working at my place. When I upload <a href="http://www.kasino888.com">kasino888</a>it on server it gives me the above error. But if I install third party mail client, my program works fine.Please help me Its urgent for me.thanks
Anonymous
2009-03-20 09:02:21
please can anybody tell me what must be substituted in place of pop3.mydomain.com
please mail the code to prashanth_desai@yahoo.com
Thanks in advance
Anonymous
2009-03-26 08:03:31
http://www.pokerstv.com
himanshi
2009-03-26 10:20:36
The javax.mail API uses a properties file for reading server names and related configuration. These settings will override any system defaults. Alternatively, the configuration can be set directly in code, using the JavaMail API. I liked thi but i am facing some problems regarding this.
http://www.onlinevegas.co.uk
Anonymous
2009-04-06 13:55:16
what is escape character
Anonymous
2009-04-21 11:06:07
Send mail using java mail API, is explained in detail at prasnah
Anonymous
2009-06-03 10:43:04
dot use pop3 mail server address.
use SMTP mail server address.
for gmail its-----smtp.gmail.com
Anonymous
2009-06-03 10:52:54
TRY THIS CODE|||||
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class TestEmail {

public static void main(String[] args) {
String to = "mudasirmms@gmail.com";
String from = "mudasirshafi1@yahoo.in";
String host = "smtp.mail.yahoo.com";

Properties props = new Properties();

props.put("mail.smtp.host", host);
props.put("mail.debug", "false");
Session session = Session.getInstance(props);

try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Test E-Mail through Java");
msg.setSentDate(new Date());

msg.setText("This is a test of sending a " +
"plain text e-mail through Java.\n" );

Transport.send(msg);
}
catch (MessagingException mex) {
mex.printStackTrace();
}
}
}
Anonymous
2009-06-05 18:39:38
I got this Error:

MailClient cannot be resolved to a type

can anybody help me?
Anonymous
2009-06-13 15:42:15
Hi,

When I execute your program, it is successfully compiled but it's throwing exceptions as below. Please tell me why and what to do to resolve this.

If you find the solution, please write a mail to me at "hello_725@rediffmail.com"
-------------------------------------------------
C:\Java>javac MailClient.java

C:\Java>java MailClient
javax.mail.MessagingException: Could not connect to SMTP host: 74.125.127.83, po
rt: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1545)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:45
3)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at javax.mail.Service.connect(Service.java:121)
at javax.mail.Transport.send0(Transport.java:190)
at javax.mail.Transport.send(Transport.java:120)
at MailClient.sendMail(MailClient.java:46)
at MailClient.main(MailClient.java:85)
Caused by: java.net.ConnectException: Connection refused: 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 java.net.Socket.connect(Unknown Source)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:267)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:227)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1511)
... 8 more

C:\Java>
C:\Java>
SAJChurchey
2009-06-14 22:19:14
The exception returns teh error that the Connection was refused. Which means the SMTP service isn't running on that IP or a firewall could be blocking your access to the SMTP port (25).
SAJChurchey
2009-06-17 22:28:49
What is a MessageRemovedException? This is not defined in the Java API so this is probably why the class is not found, unless you've written your own Exception for this.

If you have written your own exception, you will want to check your CLASSPATH variable to make sure that it is being found by the compiler.
Anonymous
2009-07-01 14:18:29
mdaumie first off you dont even have a host... there is the reason you get and exception. second your code is insanly sloppy clean it up
Anonymous
2009-07-04 17:40:51
ul 4, 2009 10:00:00 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet SCHProcessorServlet threw exception
java.lang.ClassNotFoundException: javax.mail.Address
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at com.ugc.db.DatabaseManager.shareContentFrmSCHIPTV(DatabaseManager.java:8085)
at com.ugc.sdm.SCHProcessList.shareFrmIPTV(SCHProcessList.java:941)
at com.ugc.processor.SCHProcessorServlet.doPost(SCHProcessorServlet.java:1590)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)


I got the above exception,pls help
Anonymous
2009-07-07 13:20:28
Thanks for the help solved with this.... apeksha.gholap@newgen.co.in
Anonymous
2009-07-15 07:52:46
What to do when we get this kind of exception javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmx.com, port: 25;
nested exception is:
java.net.ConnectException: Connection timed out: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1545)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:453)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at javax.mail.Service.connect(Service.java:121)
at javax.mail.Transport.send0(Transport.java:190)
at javax.mail.Transport.send(Transport.java:120)
at com.mail.MailClient.sendMail(MailClient.java:47)
at com.mail.MailClient.main(MailClient.java:85)
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 java.net.Socket.connect(Unknown Source)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:267)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:227)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1511)
Anonymous
2009-08-20 16:21:29
You can point to the port 465 by putting the property as ("mail.smtp.port", "465") but how do you set isSSL to "true"?

I am getting the 'response reading exception' as follows:

javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Connection reset
Anonymous
2009-08-28 09:10:46
thank you very much...
Anonymous
2009-10-08 17:33:13
if i want change "smtp.gmail.port" to "smtp.something.port",how is result's that code ?
Anonymous
2009-10-26 09:35:40
Hello can anyone pls help me by sending java program to send mail using POP3/imap... with smtp i have the code with me..
Thanks in Advance
My id adityavajra@gmail.com
SAJChurchey
2009-10-29 16:05:45
It's a network problem. TCP is resetting your connection before your message can be transmitted. This is most likely because of the servers security measures. If you're trying to send a message from a residential IP address, the server may interpret this as a rogue server attempting to send spam.
SAJChurchey
2009-10-29 16:09:10
You cannot SEND mail w/ IMAP or POP3. These are protocols used to retrieve mail from the server from a user's mailbox. SMTP is the protocol used to send e-mail.
Anonymous
2009-11-21 10:17:48
hi to all pls can any one help me in this issue.if so pls

when iam running the programe given above by pertinax i got the following error pls help me out.

javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Connection reset
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java
:1764)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1523)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:45
3)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at javax.mail.Service.connect(Service.java:121)
at javax.mail.Transport.send0(Transport.java:190)
at javax.mail.Transport.send(Transport.java:120)
at MailClient.sendMail(MailClient.java:45)
at MailClient.main(MailClient.java:84)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:106)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:84)
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java
:1742)
... 9 more

Anonymous
2009-12-10 11:30:13
How to Send a CSV File attachment using java mail on Fly wihtout creating on file System.
Anonymous
2009-12-12 22:59:11

com.sun.mail.smtp.SMTPSendFailedException: 530 authentication required - for help go to http://help.yahoo.com/help/us/mail/pop/pop-11.html

at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)
at javax.mail.Transport.send0(Transport.java:169)
at javax.mail.Transport.send(Transport.java:98)
at javaapplication2.Main.sendEmail(Main.java:120)
at javaapplication2.Main.main(Main.java:38)
BUILD SUCCESSFUL (total time: 1 second)
Anonymous
2009-12-12 23:04:45
When i am trying send email with attachment, I am getting the File Not Found Exception. I am uploading my file within the jsp. I have to change the forward slash(\) to backward slash(/) in my servlet code.

Please help me on this.
Anonymous
2010-01-28 09:22:23
what is SimpleSender?
Anonymous
2010-02-17 02:54:15
Thanks for your code.. your work perfectly...

need to adjust like this :-
String[] filenames =
{"c:\\somefile.txt"};

One more thing.. please include how sent to many emails. TQ


Anonymous
2010-03-07 02:41:17
help i got following exception and if anybody have code for web based email system please send me
my email id is lotababa2@yahoo.in thanx.....

javax.mail.MessagingException: Could not connect to SMTP host: pop3.mydomain.com, port: 25;
nested exception is:
java.net.ConnectException: Connection timed out: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1706)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:525)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at javax.mail.Service.connect(Service.java:121)
at javax.mail.Transport.send0(Transport.java:190)
at javax.mail.Transport.send(Transport.java:120)
at MailClient.sendMail(MailClient.java:45)
at MailClient.main(MailClient.java:84)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:525)
at java.net.Socket.connect(Socket.java:475)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:284)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:227)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1672)
... 8 more
Anonymous
2010-03-07 02:42:22
help i got following exception and if anybody have code for web based email system please send me
my email id is lotababa2@yahoo.in thanx.....

javax.mail.MessagingException: Could not connect to SMTP host: pop3.mydomain.com, port: 25;
nested exception is:
java.net.ConnectException: Connection timed out: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1706)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:525)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at javax.mail.Service.connect(Service.java:121)
at javax.mail.Transport.send0(Transport.java:190)
at javax.mail.Transport.send(Transport.java:120)
at MailClient.sendMail(MailClient.java:45)
at MailClient.main(MailClient.java:84)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:525)
at java.net.Socket.connect(Socket.java:475)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:284)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:227)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1672)
... 8 more
Anonymous
2010-03-20 07:18:56
I Tried This code
-----------------------------------
TRY THIS CODE|||||
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class TestEmail {

public static void main(String[] args) {
String to = "mudasirmms@gmail.com";
String from = "mudasirshafi1@yahoo.in";
String host = "smtp.mail.yahoo.com";

Properties props = new Properties();

props.put("mail.smtp.host", host);
props.put("mail.debug", "false");
Session session = Session.getInstance(props);

try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Test E-Mail through Java");
msg.setSentDate(new Date());

msg.setText("This is a test of sending a " +
"plain text e-mail through Java.\n" );

Transport.send(msg);
}
catch (MessagingException mex) {
mex.printStackTrace();
}
}
}
----------------------------------------
GOT THIS EXCEPTION
com.sun.mail.smtp.SMTPSendFailedException: 530 authentication required - for help go to http://help.yahoo.com/help/us/mail/pop/pop-11.html

at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1829)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1368)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:886)
at javax.mail.Transport.send0(Transport.java:191)
at javax.mail.Transport.send(Transport.java:120)
at dailybackup.TestMail.main(TestMail.java:41)
-------------------------------------------------
Please Help Me to solve this Problem
Anonymous
2010-03-21 11:43:29
i m getting authentication error while sending mail to yahoo....some one help me soon!!!!!
Anonymous
2010-09-06 13:22:13
i got exception like SMTPsendFailedException: 530 5.7.0 Must issue a STARTTLS command first. s5sm11136762wak.12
Anonymous
2010-11-10 16:04:25
nested exception is:
class javax.mail.SendFailedException: 554 Sorry, no mailbox here by that name. (#5.1.1)

can any one tell me why this problem occurred how to resolve it? thanx in advance. If you got code just mail me to srujan445@gmail.com
Anonymous
2010-11-19 12:59:56
Nobody responded for the exception what we are getting for the above code..
Plz somebody give some solution.
Anonymous
2010-12-25 17:08:42
com.sun.mail.smtp.SMTPSendFailedException: 530 authentication required - for help go to http://help.yahoo.com/help/us/mail/pop/pop-11.html

at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1829)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1368)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:886)
at javax.mail.Transport.send0(Transport.java:191)
at javax.mail.Transport.send(Transport.java:120)
at MailPackage.sendMail.sendMail(sendMail.java:52)
at MailPackage.sendMail.main(sendMail.java:90)
Anonymous
2010-12-25 17:21:41
any one with answer for the above error?
Anonymous
2010-12-31 09:19:04
where can i get somefile.txt
Anonymous
2011-03-14 09:37:02
hai,
plz send commands to my id:karthikadevi75@yahoo.com

while i run the following program
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.*;
public class Receivemail
{
public static void main(String args[])
{
Properties props=new Properties();
String host="LocalHost";
String username="eharold";
String password="mypassword";
String provider="pop3";
try
{
Session session=Session.getDefaultInstance(props,null);
Store store=session.getStore(provider);
store.connect(host,username,password);
Folder inbox=store.getFolder("INBOX");
if(inbox==null)
{
System.out.println("No INBOX");
System.exit(1);
}
inbox.open(Folder.READ_ONLY);
Message[] messages=inbox.getMessages();
for(int i=0; i<messages.length;i++)
{
System.out.println("------- Message"+(i+1) + "--------");
messages[i].writeTo(System.out);
}
inbox.close(false);
store.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}



i got such error :

javax.mail.MessagingException: Connect failed;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:148)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at Receivemail.main(Receivemail.java:18)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:232)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
at com.sun.mail.pop3.Protocol.<init>(Protocol.java:81)
at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:201)
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:144)
... 3 more
Anonymous
2011-03-25 11:30:01
please give me procedure to run this code thanks u in andvance plz help me
Anonymous
2011-03-30 16:17:56
Loads of people posting stack traces. You are all idiots.
Anonymous
2011-04-05 11:44:58
I agree
oshil
2011-04-08 06:41:36
gf ghhgjn
Anonymous
2011-05-17 07:15:08
Getting the below exception:

javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketTimeoutException: Read timed out
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1462)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1260)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
at javax.mail.Service.connect(Service.java:275)
at com.comverse.mail.SmsToSMTPClientService.connect(SmsToSMTPClientService.java:521)
at com.comverse.mail.SmsToSMTPClientService.reconnectAndSend(SmsToSMTPClientService.java:715)
Anonymous
2011-05-23 13:12:03
If i want to know that what given address in To is not feasible then how could i detect it?
ObatAsamUrat
2011-06-16 07:32:51
hey there,My spouse and i come across that your particular web site can be extremely helpful along with valuable and now we speculate in case there can be a possibility involving getting a large amount far more articles or blog posts this way with your vast world wide web web-site. In case you happy to allow us out and about, natural meats anticipate to recompense anyone .
kaos distro
Anonymous
2011-07-05 18:15:55
@ObatAsamUrat You and your spouse must be under a severe curse. 1. For wasting my effing time.
2. May Allah punish you both for... ok wait, I take it all back. I'm merciful unlike you fools!!!
Anonymously add a comment: (or register here)
(registration is really fast and we send you no spam)
BB Code is enabled.
Captcha Number:


Blogs: (People who have posted blogs on this subject..)
goldie
using javamail i am getting excetion like this on Tue 5th May 6am
avax.mail.MessagingException: Unknown SMTP host: pop3.gmail.com; nested exception is: java.net.UnknownHostException: pop3.gmail.com at com.sun.mail.smtp.SMTPTransport.openServ er(SMTPTransport.java:1543) at com.sun.mail.smtp.SMTPTransport.protocol
kdemetter
Blog entry for Wed 11th Apr 1pm on Wed 11th Apr 1pm
lately i've been playing with Java a little . I'm working on a application that can create a list of meals for one week from a large list of meals . well , it works . just some problems with Swing not doing what i want it to do :-) http://www.os

Test Yourself: (why not try testing your skill on this subject? Clicking the link will start the test.)
Java tricks by berry120

Think you really know Java? This won't test you on elaborate and never heard of APIs. It will test you on stuff that isn't always as it seems...
Java Programming - Level 1 by D-Cypell

A first level Java programming test. The test contains 10 questions on Java syntax, concepts and the API.
History and Basic Programming Knowledge by HackMaster321

A test of your knowledge of java history and programming. Tests your ability to recall java historical facts, and remember what some of javas more common commands and syntax are and do.


     
Your Ad Here
 
Copyright Open Source Institute, 2006