I need javamail help

N

news

I want to connect a email server with ssl security. I am using the attched
code, but I get the following exception:
javax.mail.MessagingException: DummySSLSocketFactory; nested
exception is:
java.net.SocketException: DummySSLSocketFactory
at
com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:335)
at javax.mail.Service.connect(Service.java:233)
at javax.mail.Service.connect(Service.java:134)

Could someone help me with that? Thank you very much. Here is the code:

private static void setProperties(Properties props)
{
Security.addProvider( new com.sun.net.ssl.internal.ssl.Provider());
Security.setProperty( "ssl.SocketFactory.provider",
"DummySSLSocketFactory");
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
// IMAP provider
props.setProperty( "mail.imap.socketFactory.class", SSL_FACTORY);
props.setProperty( "mail.imap.socketFactory.fallback", "false");
props.setProperty( "mail.imap.port", "993");
props.setProperty( "mail.imap.socketFactory.port", "993");
}

public static void receive(String popServer, String popUser
, String popPassword)
{
Store store=null;
Folder folder=null;
try
{
// -- Get hold of the default session --
Properties props = System.getProperties();
setProperties(props);
props.put("mail.debug","true");
Session session = Session.getInstance(props, null);

// -- Get hold of a POP3 message store, and connect to it --
store = session.getStore("imap");
store.connect(popServer, popUser, popPassword);

// -- ...and its INBOX --
folder = store.getFolder("INBOX");
if (folder == null) throw new Exception("No POP3 INBOX");

// -- Open the folder for read only --
folder.open(Folder.READ_ONLY);
Message[] msg = folder.getMessages();
int count = folder.getMessageCount();
for (int i = 0; i < count; i++)
{
String[] froms = msg.getHeader("From");
System.out.println(( (InternetAddress)
msg.getFrom()[0]).getAddress());
String to = "";
Address[] tos = msg.getRecipients(Message.RecipientType.TO);
for(int j=0;j<tos.length; j++)
{
to += ((InternetAddress)(tos[j])).getAddress();
}


System.out.println(((InternetAddress)(msg.getRecipients(Message.Recipient
Type.TO))[0]).getAddress());;
printMessage(msg);
}

}
catch (Exception ex)
{
ex.printStackTrace();
}
finally
{
// -- Close down nicely --
try
{
if (folder!=null) folder.close(false);
if (store!=null) store.close();
}
catch (Exception ex2) {ex2.printStackTrace();}
}
}
 
J

Jeffrey Palm

news said:
I want to connect a email server with ssl security. I am using the attched
code, but I get the following exception:
javax.mail.MessagingException: DummySSLSocketFactory; nested
exception is:
java.net.SocketException: DummySSLSocketFactory
at
com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:335)
at javax.mail.Service.connect(Service.java:233)
at javax.mail.Service.connect(Service.java:134)

Could someone help me with that? Thank you very much. Here is the code:

private static void setProperties(Properties props)
{
Security.addProvider( new com.sun.net.ssl.internal.ssl.Provider());
Security.setProperty( "ssl.SocketFactory.provider",
"DummySSLSocketFactory");
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
// IMAP provider
props.setProperty( "mail.imap.socketFactory.class", SSL_FACTORY);
props.setProperty( "mail.imap.socketFactory.fallback", "false");
props.setProperty( "mail.imap.port", "993");
props.setProperty( "mail.imap.socketFactory.port", "993");
}

public static void receive(String popServer, String popUser
, String popPassword)
{
Store store=null;
Folder folder=null;
try
{
// -- Get hold of the default session --
Properties props = System.getProperties();
setProperties(props);
props.put("mail.debug","true");
Session session = Session.getInstance(props, null);

// -- Get hold of a POP3 message store, and connect to it --
store = session.getStore("imap");
store.connect(popServer, popUser, popPassword);

// -- ...and its INBOX --
folder = store.getFolder("INBOX");
if (folder == null) throw new Exception("No POP3 INBOX");

// -- Open the folder for read only --
folder.open(Folder.READ_ONLY);
Message[] msg = folder.getMessages();
int count = folder.getMessageCount();
for (int i = 0; i < count; i++)
{
String[] froms = msg.getHeader("From");
System.out.println(( (InternetAddress)
msg.getFrom()[0]).getAddress());
String to = "";
Address[] tos = msg.getRecipients(Message.RecipientType.TO);
for(int j=0;j<tos.length; j++)
{
to += ((InternetAddress)(tos[j])).getAddress();
}


System.out.println(((InternetAddress)(msg.getRecipients(Message.Recipient
Type.TO))[0]).getAddress());;
printMessage(msg);
}

}
catch (Exception ex)
{
ex.printStackTrace();
}
finally
{
// -- Close down nicely --
try
{
if (folder!=null) folder.close(false);
if (store!=null) store.close();
}
catch (Exception ex2) {ex2.printStackTrace();}
}
}


Here's the code I use to send messages:

public void send() throws Exception {
Properties props = new Properties();
props.put("mail.smtp.host", host);
if (debug) {
props.put("mail.debug", "true");
}

Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);

Message msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(from));

addRecipients(Message.RecipientType.TO, toList, msg);
addRecipients(Message.RecipientType.CC, ccList, msg);
addRecipients(Message.RecipientType.BCC, bccList, msg);

msg.setSubject(subject);
msg.setSentDate(sentDate != null ? sentDate : new Date());

msg.setText(messageText);

Transport.send(msg);
}

private void addRecipients(Message.RecipientType type,
List addressesList,
Message msg) throws MessagingException {
if (addressesList.size() > 0) {
InternetAddress[] addresses = new
InternetAddress[addressesList.size()];
for (int i = 0; i < addresses.length; i++) {
addresses = new InternetAddress((String)addressesList.get(i));
}
msg.addRecipients(type, addresses);
}
}

Jeff
 
N

news

Thank you very much. My problem is how to retrieve message from a
SSL-secured IMAP email server. Could you help me with that? Thanks again.

Jeffrey Palm said:
news said:
I want to connect a email server with ssl security. I am using the attched
code, but I get the following exception:
javax.mail.MessagingException: DummySSLSocketFactory; nested
exception is:
java.net.SocketException: DummySSLSocketFactory
at
com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:335)
at javax.mail.Service.connect(Service.java:233)
at javax.mail.Service.connect(Service.java:134)

Could someone help me with that? Thank you very much. Here is the code:

private static void setProperties(Properties props)
{
Security.addProvider( new com.sun.net.ssl.internal.ssl.Provider());
Security.setProperty( "ssl.SocketFactory.provider",
"DummySSLSocketFactory");
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
// IMAP provider
props.setProperty( "mail.imap.socketFactory.class", SSL_FACTORY);
props.setProperty( "mail.imap.socketFactory.fallback", "false");
props.setProperty( "mail.imap.port", "993");
props.setProperty( "mail.imap.socketFactory.port", "993");
}

public static void receive(String popServer, String popUser
, String popPassword)
{
Store store=null;
Folder folder=null;
try
{
// -- Get hold of the default session --
Properties props = System.getProperties();
setProperties(props);
props.put("mail.debug","true");
Session session = Session.getInstance(props, null);

// -- Get hold of a POP3 message store, and connect to it --
store = session.getStore("imap");
store.connect(popServer, popUser, popPassword);

// -- ...and its INBOX --
folder = store.getFolder("INBOX");
if (folder == null) throw new Exception("No POP3 INBOX");

// -- Open the folder for read only --
folder.open(Folder.READ_ONLY);
Message[] msg = folder.getMessages();
int count = folder.getMessageCount();
for (int i = 0; i < count; i++)
{
String[] froms = msg.getHeader("From");
System.out.println(( (InternetAddress)
msg.getFrom()[0]).getAddress());
String to = "";
Address[] tos = msg.getRecipients(Message.RecipientType.TO);
for(int j=0;j<tos.length; j++)
{
to += ((InternetAddress)(tos[j])).getAddress();
}


System.out.println(((InternetAddress)(msg.getRecipients(Message.Recipient
Type.TO))[0]).getAddress());;
printMessage(msg);
}

}
catch (Exception ex)
{
ex.printStackTrace();
}
finally
{
// -- Close down nicely --
try
{
if (folder!=null) folder.close(false);
if (store!=null) store.close();
}
catch (Exception ex2) {ex2.printStackTrace();}
}
}


Here's the code I use to send messages:

public void send() throws Exception {
Properties props = new Properties();
props.put("mail.smtp.host", host);
if (debug) {
props.put("mail.debug", "true");
}

Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);

Message msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(from));

addRecipients(Message.RecipientType.TO, toList, msg);
addRecipients(Message.RecipientType.CC, ccList, msg);
addRecipients(Message.RecipientType.BCC, bccList, msg);

msg.setSubject(subject);
msg.setSentDate(sentDate != null ? sentDate : new Date());

msg.setText(messageText);

Transport.send(msg);
}

private void addRecipients(Message.RecipientType type,
List addressesList,
Message msg) throws MessagingException {
if (addressesList.size() > 0) {
InternetAddress[] addresses = new
InternetAddress[addressesList.size()];
for (int i = 0; i < addresses.length; i++) {
addresses = new InternetAddress((String)addressesList.get(i));
}
msg.addRecipients(type, addresses);
}
}

Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top