use of javax.mail.NoSuchProviderException in project jodd by oblac.
the class Pop3Server method createSession.
/**
* {@inheritDoc}
*/
public ReceiveMailSession createSession() {
Session session = Session.getInstance(sessionProperties, authenticator);
Store store;
try {
store = getStore(session);
} catch (NoSuchProviderException nspex) {
throw new MailException("Failed to create POP3 session", nspex);
}
return new ReceiveMailSession(session, store);
}
use of javax.mail.NoSuchProviderException in project symmetric-ds by JumpMind.
the class MailService method testTransport.
public String testTransport(TypedProperties prop) {
String error = null;
Transport transport = null;
try {
Session session = Session.getInstance(getJavaMailProperties(prop));
transport = session.getTransport(prop.get(ParameterConstants.SMTP_TRANSPORT, "smtp"));
if (prop.is(ParameterConstants.SMTP_USE_AUTH, false)) {
transport.connect(prop.get(ParameterConstants.SMTP_USER), prop.get(ParameterConstants.SMTP_PASSWORD));
} else {
transport.connect();
}
} catch (NoSuchProviderException e) {
error = getNestedErrorMessage(e);
} catch (MessagingException e) {
error = getNestedErrorMessage(e);
} finally {
try {
if (transport != null) {
transport.close();
}
} catch (MessagingException e) {
}
}
return error;
}
use of javax.mail.NoSuchProviderException in project symmetric-ds by JumpMind.
the class MailService method sendEmail.
protected String sendEmail(String subject, String text, String recipients, Properties prop, String transportType, boolean useAuth, String user, String password) {
Session session = Session.getInstance(prop);
ByteArrayOutputStream ba = null;
if (log.isDebugEnabled()) {
session.setDebug(true);
ba = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(ba);
session.setDebugOut(ps);
}
Transport transport;
try {
transport = session.getTransport(transportType);
} catch (NoSuchProviderException e) {
log.error("Failure while obtaining transport", e);
return getNestedErrorMessage(e);
}
try {
if (useAuth) {
transport.connect(user, password);
} else {
transport.connect();
}
} catch (MessagingException e) {
log.error("Failure while connecting to transport", e);
return getNestedErrorMessage(e);
}
try {
MimeMessage message = new MimeMessage(session);
message.setSentDate(new Date());
message.setRecipients(RecipientType.BCC, recipients);
message.setSubject(subject);
message.setText(text);
try {
transport.sendMessage(message, message.getAllRecipients());
} catch (MessagingException e) {
log.error("Failure while sending notification", e);
return getNestedErrorMessage(e);
}
} catch (MessagingException e) {
log.error("Failure while preparing notification", e);
return e.getMessage();
} finally {
try {
transport.close();
} catch (MessagingException e) {
}
}
if (log.isDebugEnabled()) {
log.debug(ba.toString());
}
return null;
}
use of javax.mail.NoSuchProviderException in project Gargoyle by callakrsos.
the class MailPopReceiver method receiveEmail.
public void receiveEmail() {
try {
//1) get the session object
//new Properties();
Properties properties = System.getProperties();
properties.put("mail.pop3.host", popHost);
properties.put("mail.user", userName);
properties.put("mail.from", hostEmailAddr);
properties.put("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.put("mail.pop3.socketFactory.port", "995");
properties.put("mail.pop3.port", "995");
properties.setProperty("mail.pop3.socketFactory.fallback", "false");
if (this.proxy != null) {
String hostName = proxy.getHostName();
int port = proxy.getPort();
String value = port + "";
properties.put("proxySet", "true");
properties.put("socksProxyHost", hostName);
properties.put("socksProxyPort", value);
properties.put("http.proxyHost", hostName);
properties.put("http.proxyPort", port + "");
properties.put("https.proxyHost", hostName);
properties.put("https.proxyPort", port + "");
//#####################################
properties.setProperty("proxySet", "true");
properties.setProperty("socksProxyHost", hostName);
properties.setProperty("socksProxyPort", port + "");
properties.setProperty("http.proxyHost", hostName);
properties.setProperty("http.proxyPort", port + "");
properties.setProperty("https.proxyHost", hostName);
properties.setProperty("https.proxyPort", port + "");
}
Authenticator authenticator = new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(hostEmailAddr, password);
}
};
Session emailSession = Session.getInstance(properties, authenticator);
// Session emailSession = Session.getDefaultInstance(properties);
emailSession.setDebug(debug);
//2) create the POP3 store object and connect with the pop server
// POP3Store emailStore = (POP3Store) emailSession.getStore(type);
URLName url = new URLName(type, popHost, 995, "", hostEmailAddr, password);
POP3SSLStore emailStore = new POP3SSLStore(emailSession, url);
System.out.println(emailStore.isSSL());
emailStore.connect();
System.out.println("connected.");
//3) create the folder object and open it
Folder emailFolder = emailStore.getFolder("INBOX");
emailFolder.open(Folder.READ_ONLY);
//4) retrieve the messages from the folder in an array and print it
Message[] messages = emailFolder.getMessages();
for (int i = 0; i < messages.length; i++) {
Message message = messages[i];
System.out.println("---------------------------------");
System.out.println("Email Number " + (i + 1));
System.out.println("Subject: " + message.getSubject());
System.out.println("From: " + message.getFrom()[0]);
System.out.println("Text: " + message.getContent().toString());
}
//5) close the store and folder objects
emailFolder.close(false);
emailStore.close();
} catch (NoSuchProviderException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
use of javax.mail.NoSuchProviderException in project opennms by OpenNMS.
the class JavaReadMailer method retrieveMessages.
/*
* TODO: Need readers that:
* - use FetchProfiles
* - make use of pre-fetch nature of getMessages()
* - A reader for the entire system could be implemented using events/event listeners
* TODO: Need to make this more efficient... probably needs state so that message contents can be retrieved from the
* store after they are read via this message.
*/
/**
* <p>retrieveMessages</p>
*
* @param term a {@link javax.mail.search.SearchTerm} object.
* @return a {@link java.util.List} object.
* @throws org.opennms.javamail.JavaMailerException if any.
*/
public List<Message> retrieveMessages(SearchTerm term) throws JavaMailerException {
Message[] msgs;
Folder mailFolder = null;
final ReadmailHost readmailHost = getReadmailHost(m_config);
final UserAuth userAuth = getUserAuth(m_config);
try {
Store store = m_session.getStore(readmailHost.getReadmailProtocol().getTransport());
store.connect(readmailHost.getHost(), (int) readmailHost.getPort(), userAuth.getUserName(), userAuth.getPassword());
mailFolder = store.getFolder(m_config.getMailFolder());
mailFolder.open(Folder.READ_WRITE);
msgs = mailFolder.search(term);
} catch (NoSuchProviderException e) {
throw new JavaMailerException("No provider matching:" + readmailHost.getReadmailProtocol().getTransport() + " from config:" + m_config.getName(), e);
} catch (MessagingException e) {
throw new JavaMailerException("Problem reading messages from configured mail store", e);
}
List<Message> msgList = Arrays.asList(msgs);
return msgList;
}
Aggregations