use of javax.mail.NoSuchProviderException in project selenium-tests by Wikia.
the class EmailUtils method deleteAllEmails.
public static void deleteAllEmails(String userName, String password) {
try {
// establishing connections
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
Session session = Session.getDefaultInstance(props, null);
session.setDebug(false);
Store store = session.getStore("imaps");
store.connect("imap.googlemail.com", userName, password);
// getInbox
Folder inbox = store.getFolder("Inbox");
inbox.open(Folder.READ_WRITE);
Message[] messages = inbox.getMessages();
if (messages.length != 0) {
for (int i = 0; i < messages.length; i++) {
messages[i].setFlag(Flags.Flag.DELETED, true);
}
} else {
PageObjectLogging.log("Mail", "There are no messages in inbox", true);
}
store.close();
} catch (NoSuchProviderException e) {
PageObjectLogging.log("Mail", e, false);
} catch (MessagingException e) {
PageObjectLogging.log("Mail", e, false);
}
}
use of javax.mail.NoSuchProviderException in project selenium-tests by Wikia.
the class EmailUtils method getFirstEmailContent.
public static String getFirstEmailContent(String userName, String password, String subject) {
try {
PageObjectLogging.logInfo("Checking emails for " + userName + " that contain '" + subject + "'");
// establishing connections
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("imap.googlemail.com", userName, password);
// getInbox
Folder inbox = store.getFolder("Inbox");
inbox.open(Folder.READ_ONLY);
Message[] messages = null;
boolean forgottenPasswordMessageFound = false;
Message magicMessage = null;
for (int i = 0; !forgottenPasswordMessageFound; i++) {
messages = inbox.getMessages();
PageObjectLogging.log("Mail", "Waiting for the message", true);
Thread.sleep(2000);
for (Message message : messages) {
if (message.getSubject().contains(subject)) {
forgottenPasswordMessageFound = true;
magicMessage = message;
}
}
if (i > 15) {
throw new WebDriverException("Mail timeout exceeded");
}
}
PageObjectLogging.log("Mail", "Mail arrived", true);
Message m = magicMessage;
String line;
StringBuilder builder = new StringBuilder();
InputStreamReader in = new InputStreamReader(m.getInputStream());
BufferedReader reader = new BufferedReader(in);
while ((line = reader.readLine()) != null) {
builder.append(line);
}
store.close();
return builder.toString();
} catch (NoSuchProviderException e) {
PageObjectLogging.log("getFirstEmailContent", e, false);
throw new WebDriverException();
} catch (MessagingException | IOException | InterruptedException e) {
PageObjectLogging.log("getFirstEmailContent", e, false);
throw new WebDriverException();
}
}
use of javax.mail.NoSuchProviderException in project Activiti by Activiti.
the class JndiEmailTest method setUp.
@BeforeClass
public void setUp() {
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.provider.class", MockEmailTransport.class.getName());
props.put("mail.smtp.class", MockEmailTransport.class.getName());
props.put("mail.smtp.provider.vendor", "test");
props.put("mail.smtp.provider.version", "0.0.0");
Provider provider = new Provider(Type.TRANSPORT, "smtp", MockEmailTransport.class.getName(), "test", "1.0");
Session mailSession = Session.getDefaultInstance(props);
SimpleNamingContextBuilder builder = null;
try {
mailSession.setProvider(provider);
builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
builder.bind("java:comp/env/Session", mailSession);
} catch (NamingException e) {
logger.error("Naming error in email setup", e);
} catch (NoSuchProviderException e) {
logger.error("provider error in email setup", e);
}
}
use of javax.mail.NoSuchProviderException in project ats-framework by Axway.
the class MailSender method initSession.
/**
* Initialize the SMTP session
*
* @throws ActionException
*/
private void initSession() throws ActionException {
// initialize the mail session with the current properties
session = Session.getInstance(mailProperties);
// user can get more debug info with the session's debug mode
session.setDebug(configurator.getMailSessionDebugMode());
// initialize the SMPT transport
try {
transport = session.getTransport("smtp");
} catch (NoSuchProviderException e) {
throw new ActionException(e);
}
}
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();
}
}
Aggregations