Pooja psharma

Greenhorn
+ Follow
since Jan 29, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Pooja psharma

I tried including the 2jars...but I'm still getting the same error.
Even tried downloading the latest ones and ftping it under binary mode...but don't know why i still get this error.

i set my classpath as:
export CLASSPATH=$CLASSPATH:/tools/jdk150_18/jre
export CLASSPATH=$CLASSPATH:/export/home/.../SSL-jars/lib
export CLASSPATH=$CLASSPATH:/export/home/.../SSL-jars/mail.jar
export CLASSPATH=$CLASSPATH:/export/home/.../SSL-jars/activation.jar:.

and then try compiling my program...but get this:

$ javac SimpleMailExample.java
error: error reading /export/home/..../mail.jar; invalid END header (bad central directory offset)
lsSimpleMailExample.java:1: package javax.mail does not exist
import javax.mail.*;
^
SimpleMailExample.java:2: package javax.mail.internet does not exist
import javax.mail.internet.*;
^
SimpleMailExample.java:27: cannot find symbol
symbol : class Session
location: class SimpleMailExample
Session session = Session.getDefaultInstance(props,
^
SimpleMailExample.java:28: package javax.mail does not exist
new javax.mail.Authenticator() {

What is it that I'm missing here...please help!

11 years ago
Yes, that's right...same machine
11 years ago
Sumit,
I tried pinging the IP from my local command prompt..and the request timed out
11 years ago
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)...
11 years ago
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??
11 years ago

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??
11 years ago
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...
11 years ago
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.


package Mail;

import java.security.Security;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class SimpleMail
{
private String mailhost = "abc.com";
//private String mailhost = "smtp.gmail.com";

public synchronized void sendMail(String subject, String body, String sender, String recipients)
throws Exception
{

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

Properties props = new Properties();
props.setProperty("mail.transport.protocol","smtp");
props.setProperty("mail.host",mailhost);
props.put("mail.smtp.auth","true");
props.put("mail.smtp.port","25");
props.put("mail.smtp.socketFactory.port","25");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback","false");
props.setProperty("mail.smtp.quitwait","false");

Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{ return new PasswordAuthentication("userid","password"); }
});

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...
11 years ago