use of javax.mail.MessagingException in project zm-mailbox by Zimbra.
the class SmtpTransportTest method noAuthMechansims.
@Test(timeout = 3000)
public void noAuthMechansims() throws Exception {
server = MockTcpServer.scenario().sendLine("220 test ready").recvLine().sendLine("250-OK").sendLine("250 AUTH NTLM").build().start(PORT);
Session session = JMSession.getSession();
Transport transport = session.getTransport("smtp");
try {
transport.connect("localhost", PORT, "zimbra", "secret");
Assert.fail();
} catch (MessagingException e) {
Assert.assertEquals("No auth mechanism supported: [NTLM]", e.getMessage());
}
server.shutdown(1000);
}
use of javax.mail.MessagingException in project zm-mailbox by Zimbra.
the class SmtpTransportTest method noAuth.
@Test(timeout = 3000)
public void noAuth() throws Exception {
server = MockTcpServer.scenario().sendLine("220 test ready").recvLine().sendLine("250 OK").build().start(PORT);
Session session = JMSession.getSession();
Transport transport = session.getTransport("smtp");
try {
transport.connect("localhost", PORT, "zimbra", "secret");
Assert.fail();
} catch (MessagingException e) {
Assert.assertEquals("The server doesn't support SMTP-AUTH.", e.getMessage());
}
server.shutdown(1000);
}
use of javax.mail.MessagingException in project zm-mailbox by Zimbra.
the class SendShareNotificationTest method generateShareNotification.
@Override
protected MimeMessage generateShareNotification(Account authAccount, Account ownerAccount, ShareInfoData sid, String notes, SendShareNotificationRequest.Action action, Collection<String> internalRecipients, String externalRecipient) throws ServiceException, MessagingException {
MimeMessage mm = super.generateShareNotification(authAccount, ownerAccount, sid, notes, action, internalRecipients, externalRecipient);
try {
MimeMultipart mmp = (MimeMultipart) mm.getContent();
BodyPart bp = mmp.getBodyPart(2);
Assert.assertTrue(bp.getContentType().startsWith(MimeConstants.CT_XML_ZIMBRA_SHARE));
Element share = Element.parseXML(bp.getInputStream());
if (revoke) {
Assert.assertEquals(share.getQName().getName(), MailConstants.ShareConstants.E_REVOKE);
} else {
Assert.assertEquals(share.getQName().getName(), MailConstants.ShareConstants.E_SHARE);
}
} catch (Exception e) {
Assert.fail(e.getMessage());
}
return mm;
}
use of javax.mail.MessagingException in project pratilipi by Pratilipi.
the class EmailUtil method sendMail.
public static void sendMail(String senderName, String senderEmail, InternetAddress[] recipients, InternetAddress[] cc, String subject, String body) throws UnexpectedServerException {
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(senderEmail, senderName));
msg.addRecipients(Message.RecipientType.TO, recipients);
msg.addRecipients(Message.RecipientType.CC, cc);
// TODO: Uncomment when we migrate to other email service providers
// msg.addRecipient( Message.RecipientType.BCC, new InternetAddress( "mail-archive@pratilipi.com", "Mail Archive" ) );
msg.setSubject(subject);
msg.setContent(body, "text/html; charset=UTF-8");
logger.log(Level.INFO, "Sending mail");
Transport.send(msg);
} catch (UnsupportedEncodingException | MessagingException e) {
// logger.log( Level.SEVERE, "Failed to send mail to " + recipientEmail + ".", e );
throw new UnexpectedServerException();
}
}
use of javax.mail.MessagingException in project ats-framework by Axway.
the class Test_MailReportSender method errorOnSend.
@Test(expected = MailReportSendException.class)
public void errorOnSend() throws MessagingException {
mockStatic(Transport.class);
expect(ReportConfigurator.getInstance()).andReturn(mockReportConfigurator);
expect(mockReportConfigurator.getSmtpServerName()).andReturn("localhost");
expect(mockReportConfigurator.getSmtpServerPort()).andReturn("25");
expect(mockReportConfigurator.getAddressesTo()).andReturn(new String[] { "userTo" });
expect(mockReportConfigurator.getAddressesCc()).andReturn(new String[0]);
expect(mockReportConfigurator.getAddressesBcc()).andReturn(new String[0]);
expect(mockReportConfigurator.getAddressFrom()).andReturn("userFrom");
Transport.send(isA(Message.class));
expectLastCall().andThrow(new MessagingException());
replayAll();
triggerRun();
verifyAll();
}
Aggregations