This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Hi,
I am using the following code to connect to outlook and send a mail...but it gives me a "exception reading response..." error and does not send mail through Outlook.
MimeMessage message = new MimeMessage(session);
message.setSender(new InternetAddress(sender));
message.setSubject(subject);
message.setContent(body, "text/plain");
if (recipients.indexOf(',') > 0)
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
else
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
Transport.send(message);
}
public static void main(String args[]) throws Exception
{
SimpleMail mailutils = new SimpleMail();
mailutils.sendMail("test", "test", "p.kk@sprint.com", "p.kk@sprint.com");
}
}
and i get the following error:
Exception in thread "main" 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:412)
at javax.mail.Service.connect(Service.java:310)
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 Mail.SimpleMail.sendMail(SimpleMail.java:53)
at Mail.SimpleMail.main(SimpleMail.java:62)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:293)
at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:331)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:830)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.waitForClose(SSLSocketImpl.java:1555)
at com.sun.net.ssl.internal.ssl.HandshakeOutStream.flush(HandshakeOutStream.java:103)
at com.sun.net.ssl.internal.ssl.Handshaker.kickstart(Handshaker.java:626)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.kickstartHandshake(SSLSocketImpl.java:1272)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1169)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:785)
at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:110)
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:88)
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1589)
... 9 more
It works perfectly fine when I use the gmail smtp....but it errors out with the above exception when I try to use the Outlook SMTP. Is outlook restricting my program from using it to send mails? or am I using the wrong smtp host....??
Please let me know if I missed something...
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2407
posted
1
Outlook is an email client; it is not accessible via SMTP. What, precisely, are you trying to do?
Pooja psharma
Greenhorn
Joined: Jan 29, 2008
Posts: 8
posted
0
Tim,
I am trying to read some email ids from an excel and shoot a mail to those ids using my outlook account.
Am I using a wrong approach? My java program currently reads values from an excel sheet and I thought the program below will help me take each of the ids and send them a mail. But I want the mail to be sent from my outlook. Hence got stuck...
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2407
posted
0
It doesn't matter where the data originates from, Excel or otherwise, since the problem is apparently with the email part.
But again:
Outlook is an email client; it is not accessible via SMTP.
... and you won't be able to use it to send mails using JavaMail. Maybe you're just confused about terminology, and are actually trying to use some email server?
Pooja psharma
Greenhorn
Joined: Jan 29, 2008
Posts: 8
posted
0
Yes, maybe you are right.
My main concern here is to use my outlook account to send mails when I give it a list of addresses[email ids].
But can we not use webmail or find out the configurations of Microsoft Exchange Server and provide it in the program?? if not accessible via smtp, then which other protocol can I use? Also, where can I find the port and related details for MS exchange server?
I have seen threads that use MS Exchange server and some even say they are using Outlook, so is it not what I'm trying to accomplish as well??
You can get the server details from the Outlook itself. I guess its there in the Tools----> Accounts option, although not sure.
Once you get the server details, i think you can use it along with your credentials to send the email.
Thanks Sumit.
I tried that as well. I picked up the server details following Tools -> Accounts. But I feel the connection is happening fine. But not too sure about the exception I recieve.
Looks like either the port used is different from 25. Or Outlook is blocking external apps(in this case, my java program) from using Outlook.
Can you make out what the above error is??
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2407
posted
0
That makes it clearer. You want to send mails via the Exchange server using the account credentials that are also used by your Outlook client. In that case, SMTP is indeed the protocol to be used. All details (including the correct port number) would have had to be set up in Outlook, so you can look them up there. Are you using the correct value for the "mailhost" property?
Pooja psharma wrote:Or Outlook is blocking external apps(in this case, my java program) from using Outlook.
You are not using Outlook at all; it has nothing whatsoever to do with this.
Unlikely; that would block Outlook's connections just like JavaMail's connections.
Pooja psharma
Greenhorn
Joined: Jan 29, 2008
Posts: 8
posted
0
Thanks Tim!
I am also thinking on the same lines of 'mailhost' property not being right.
So where can I look it up? I tried digging Tools->Email accounts-> clicking on MS exchange link...and all I get is an address which when I use, I get an unknown SMTP host Excpetion.
Also, any idea what this error/exception indicates?
Exception in thread "main" 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:412)
at javax.mail.Service.connect(Service.java:310)
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 Mail.SimpleMail.sendMail(SimpleMail.java:53)
at Mail.SimpleMail.main(SimpleMail.java:62)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:293)
at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:331)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:830)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1170)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:785)
at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:110)
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:88)
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1589)...