Search in sources :

Example 41 with MessagingException

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);
}
Also used : MessagingException(javax.mail.MessagingException) Transport(javax.mail.Transport) JMSession(com.zimbra.cs.util.JMSession) Session(javax.mail.Session) Test(org.junit.Test)

Example 42 with MessagingException

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);
}
Also used : MessagingException(javax.mail.MessagingException) Transport(javax.mail.Transport) JMSession(com.zimbra.cs.util.JMSession) Session(javax.mail.Session) Test(org.junit.Test)

Example 43 with MessagingException

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;
}
Also used : BodyPart(javax.mail.BodyPart) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) Element(com.zimbra.common.soap.Element) MessagingException(javax.mail.MessagingException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException)

Example 44 with MessagingException

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();
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) UnexpectedServerException(com.pratilipi.common.exception.UnexpectedServerException) Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 45 with MessagingException

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();
}
Also used : Message(javax.mail.Message) MessagingException(javax.mail.MessagingException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

MessagingException (javax.mail.MessagingException)343 MimeMessage (javax.mail.internet.MimeMessage)135 IOException (java.io.IOException)126 InternetAddress (javax.mail.internet.InternetAddress)70 MimeMultipart (javax.mail.internet.MimeMultipart)64 MimeBodyPart (javax.mail.internet.MimeBodyPart)63 Message (javax.mail.Message)49 Properties (java.util.Properties)45 Session (javax.mail.Session)45 InputStream (java.io.InputStream)43 Date (java.util.Date)34 Address (javax.mail.Address)33 PackageException (com.axway.ats.action.objects.model.PackageException)32 ArrayList (java.util.ArrayList)32 NoSuchMimePackageException (com.axway.ats.action.objects.model.NoSuchMimePackageException)31 PublicAtsApi (com.axway.ats.common.PublicAtsApi)31 ServiceException (com.zimbra.common.service.ServiceException)30 ByteArrayInputStream (java.io.ByteArrayInputStream)26 DataHandler (javax.activation.DataHandler)25 UnsupportedEncodingException (java.io.UnsupportedEncodingException)24