Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java API
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Other JSE/JEE APIs
Error while sending a mail using javaMail - reg.
dinesh Venkatesan
Ranch Hand
Posts: 134
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Friends,
I am getting the following error message while trying to run a simple JavaMail program.
My code is :
import java.util.*; import javax.mail.*; import javax.mail.internet.*; import javax.mail.Authenticator; public class SimpleMailSender { public static void main( String[] args ) { try { String smtpServer = args[0]; String to = args[1]; String from = args[2]; String subject = args[3]; String body = args[4]; java.security.Security.addProvider ( new com.sun.net.ssl.internal.ssl.Provider() ); Properties props = new Properties ( System.getProperties() ); props.put("mail.smtp.starttls.enable", "true" ); props.put("mail.smtp.host",smtpServer); props.put("mail.transport.protocol","smtp"); props.put("mail.smtps.auth","true"); Session session = Session.getDefaultInstance(props,(new MyMailAuthenticator())); Message msg = new MimeMessage( session ); msg.setFrom ( new InternetAddress (from) ); msg.setRecipients( Message.RecipientType.TO, InternetAddress.parse ( to,false ) ); msg.setSubject(subject); msg.setHeader("X-Mailer","Shivsoft Mail"); msg.setSentDate(new Date()); Transport.send(msg); System.out.println("Message sent successfully"); }catch( Exception exception ) { exception.printStackTrace(); } } }
Exceptions:
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 SimpleMailSender.main(SimpleMailSender.java:27) Caused by: java.net.SocketException: Connection reset at java.net.SocketInputStream.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) ... 8 more
Can anybody help to know where am i going wrong?
thanks and regards,
dinesh Venkatesan.
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
MS Exchange Server... javamail.. Exception.. plz help
Exception in sending a mail
SecurityException while sending to gmail from javamail
Problem regarding JavaMail
Error in sending mail using ssl server
More...