Tabnine Logo
MessagingException
Code IndexAdd Tabnine to your IDE (free)

How to use
MessagingException
in
javax.mail

Best Java code snippets using javax.mail.MessagingException (Showing top 20 results out of 2,286)

Refine searchRefine arrow

  • MimeMessage
  • IMAPProtocol
  • FolderClosedException
  • InternetAddress
  • IMAPFolder
  • Session
  • Properties
origin: igniterealtime/Openfire

@Override
public void run() {
  try {
    sendMessages();
  }
  catch (MessagingException me) {
    Log.error(me.getMessage(), me);
  }
}
origin: apache/nifi

@Override
public void process(final InputStream rawIn) throws IOException {
  try (final InputStream in = new BufferedInputStream(rawIn)) {
    Properties props = new Properties();
    props.put("mail.mime.address.strict", requireStrictAddresses);
    Session mailSession = Session.getInstance(props);
    MimeMessage originalMessage = new MimeMessage(mailSession, in);
    MimeMessageParser parser = new MimeMessageParser(originalMessage).parse();
    Address[] from = originalMessage.getFrom();
    if (from == null) {
      throw new MessagingException("Message failed RFC-2822 validation: No Sender");
    Date sentDate = originalMessage.getSentDate();
    if (sentDate == null ) {
      throw new MessagingException("Message failed RFC-2822 validation: No Sent Date");
    } else if (capturedHeadersList.size() > 0){
      Enumeration headers = originalMessage.getAllHeaders();
origin: stackoverflow.com

args.writeString(Integer.toString(start) + ":" + Integer.toString(end));
args.writeString("BODY[]");
Response[] r = protocol.command("FETCH", args);
Response response = r[r.length - 1];
if (response.isOK()) {
  Properties props = new Properties();
  props.setProperty("mail.store.protocol", "imap");
  props.setProperty("mail.mime.base64.ignoreerrors", "true");
  props.setProperty("mail.imap.partialfetch", "false");
  props.setProperty("mail.imaps.partialfetch", "false");
        Contents.getContents(mm, i);
      } catch (MessagingException e) {
        e.printStackTrace();
protocol.notifyResponseHandlers(r);
protocol.handleResult(response);
origin: pentaho/pentaho-kettle

 if ( secureConnectionType.equals( "TLS" ) ) {
  props.put( "mail.smtp.starttls.enable", "true" );
 } else {
  props.put( "mail.smtps.quitwait", "false" );
Session session = Session.getInstance( props );
session.setDebug( log.isDebug() );
 Message msg = new MimeMessage( session );
   sender_address = sender_name + '<' + sender_address + '>';
  msg.setFrom( new InternetAddress( sender_address ) );
 } else {
  throw new MessagingException( BaseMessages.getString( PKG, "JobMail.Error.ReplyEmailNotFilled" ) );
 result.setNrErrors( 1 );
} catch ( MessagingException mex ) {
 logError( "Problem while sending message: " + mex.toString() );
 result.setNrErrors( 1 );
   ex = ( (MessagingException) ex ).getNextException();
  } else {
   ex = null;
origin: apache/nifi

@Override
public void process(final InputStream rawIn) throws IOException {
  try (final InputStream in = new BufferedInputStream(rawIn)) {
    Properties props = new Properties();
    props.put("mail.mime.address.strict", requireStrictAddresses);
    Session mailSession = Session.getInstance(props);
    MimeMessage originalMessage = new MimeMessage(mailSession, in);
    MimeMessageParser parser = new MimeMessageParser(originalMessage).parse();
    Address[] from = originalMessage.getFrom();
    if (from == null) {
      throw new MessagingException("Message failed RFC-2822 validation: No Sender");
    Date sentDate = originalMessage.getSentDate();
    if (sentDate == null) {
      throw new MessagingException("Message failed RFC2822 validation: No Sent Date");
origin: opensourceBIM/BIMserver

public void send() throws MessagingException, UserException {
  Properties props = new Properties();
  ServerSettings serverSettings = bimServer.getServerSettingsCache().getServerSettings();
  props.put("mail.smtp.localhost", "bimserver.org");
  String smtpProps = serverSettings.getSmtpProtocol() == SmtpProtocol.SMTPS ? "mail.smtps.port" : "mail.smtp.port";
  props.put("mail.smtp.connectiontimeout", 10000);
  props.put("mail.smtp.timeout", 10000);
  props.put("mail.smtp.writetimeout", 10000);
  Session mailSession = Session.getInstance(props);
    Message message = new MimeMessage(mailSession);
    message.setSubject(subject);
    message.setRecipients(to, addressTo);
    LOGGER.error("Error sending email " + body + " " + e.getMessage());
    throw new UserException("Error sending email " + e.getMessage());
origin: stackoverflow.com

final String password = "your.password";
Properties props = new Properties();
props.put("mail.smtp.auth", true);
props.put("mail.smtp.starttls.enable", true);
  message.setFrom(new InternetAddress("from.mail.id@gmail.com"));
  message.setRecipients(Message.RecipientType.TO,
      InternetAddress.parse("to.mail.id@gmail.com"));
  e.printStackTrace();
origin: javax.mail/com.springsource.javax.mail

private void setReplyTo(final Message msg, final Properties props) {
  final String reply = props.getProperty("mail.reply.to");
  if (reply != null && reply.length() > 0) {
    try {
      final Address[] address = InternetAddress.parse(reply, false);
      if (address != null && address.length > 0) {
        msg.setReplyTo(address);
      }
    } catch (final MessagingException ME) {
      reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
    }
  }
}
origin: stackoverflow.com

 Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
try {
  Session session = Session.getDefaultInstance(props, null);
  javax.mail.Store store = session.getStore("imaps");
  store.connect("imap.gmail.com", "<username>@gmail.com", "<password>");
  javax.mail.Folder[] folders = store.getDefaultFolder().list("*");
  for (javax.mail.Folder folder : folders) {
    if ((folder.getType() & javax.mail.Folder.HOLDS_MESSAGES) != 0) {
      System.out.println(folder.getFullName() + ": " + folder.getMessageCount());
    }
  }
} catch (MessagingException e) {
  e.printStackTrace();
}
origin: pentaho/pentaho-kettle

  data.props.put( "mail.smtp.starttls.enable", "true" );
 } else {
  protocol = "smtps";
  data.props.put( "mail.smtps.quitwait", "false" );
data.props.put( "mail." + protocol + ".host", server );
if ( port != -1 ) {
 data.props.put( "mail." + protocol + ".port", "" + port ); // needs to be supplied as a string, not as an integer
Session session = Session.getInstance( data.props );
session.setDebug( isDebug() );
Message msg = new MimeMessage( session );
  email_address = senderName + '<' + email_address + '>';
 msg.setFrom( new InternetAddress( email_address ) );
} else {
 throw new MessagingException( BaseMessages.getString( PKG, "Mail.Error.ReplyEmailNotFilled" ) );
  address[i] = new InternetAddress( reply_Address_List[i] );
InternetAddress[] address = new InternetAddress[destinations.length];
for ( int i = 0; i < destinations.length; i++ ) {
 address[i] = new InternetAddress( destinations[i] );
origin: aa112901/remusic

props.put("mail.smtp.host", "smtp.163.com");
props.put("mail.smtp.auth", "true");
Session session = Session.getInstance(props, null);
Transport transport = session.getTransport("smtp");
Address from = new InternetAddress("remusic_log@163.com");
mailMessage.setFrom(from);
Address to = new InternetAddress("remusic_log@163.com");
mailMessage.setRecipient(Message.RecipientType.TO, to);
mailMessage.setSubject(title);
ex.printStackTrace();
origin: 0opslab/opslabJutil

try {
  InternetAddress from = new InternetAddress(sender_username);
  message.setFrom(from);
  InternetAddress to = new InternetAddress(receiveUser);
  message.setRecipient(Message.RecipientType.TO, to);//还可以有CC、BCC
  message.setSubject(subject);
  message.saveChanges();
  transport = session.getTransport("smtp");
      transport.close();
    } catch (MessagingException e) {
      e.printStackTrace();
origin: stackoverflow.com

message.setFrom(new InternetAddress(from));
InternetAddress[] toAddress = new InternetAddress[to.length];
  toAddress[i] = new InternetAddress(to[i]);
  message.addRecipient(Message.RecipientType.TO, toAddress[i]);
message.setSubject(subject);
message.setText(body);
Transport transport = session.getTransport("smtp");
transport.connect(host, from, pass);
transport.sendMessage(message, message.getAllRecipients());
me.printStackTrace();
origin: com.sun.mail/javax.mail

/**
 * Computes the default to-address if none was specified.  This can
 * fail if the local address can't be computed.
 * @param msg the message
 * @param type the recipient type.
 * @since JavaMail 1.5.0
 */
private void setDefaultRecipient(final Message msg,
    final Message.RecipientType type) {
  try {
    Address a = InternetAddress.getLocalAddress(getSession(msg));
    if (a != null) {
      msg.setRecipient(type, a);
    } else {
      final MimeMessage m = new MimeMessage(getSession(msg));
      m.setFrom(); //Should throw an exception with a cause.
      Address[] from = m.getFrom();
      if (from.length > 0) {
        msg.setRecipients(type, from);
      } else {
        throw new MessagingException("No local address.");
      }
    }
  } catch (MessagingException | RuntimeException ME) {
    reportError("Unable to compute a default recipient.",
        ME, ErrorManager.FORMAT_FAILURE);
  }
}
origin: spring-projects/spring-framework

private InternetAddress parseAddress(String address) throws MessagingException {
  InternetAddress[] parsed = InternetAddress.parse(address);
  if (parsed.length != 1) {
    throw new AddressException("Illegal address", address);
  }
  InternetAddress raw = parsed[0];
  try {
    return (getEncoding() != null ?
        new InternetAddress(raw.getAddress(), raw.getPersonal(), getEncoding()) : raw);
  }
  catch (UnsupportedEncodingException ex) {
    throw new MessagingException("Failed to parse embedded personal name to correct encoding", ex);
  }
}
origin: spring-projects/spring-framework

@Test
public void failedMimeMessage() throws MessagingException {
  MockJavaMailSender sender = new MockJavaMailSender();
  sender.setHost("host");
  sender.setUsername("username");
  sender.setPassword("password");
  MimeMessage mimeMessage1 = sender.createMimeMessage();
  mimeMessage1.setRecipient(Message.RecipientType.TO, new InternetAddress("he@mail.org"));
  mimeMessage1.setSubject("fail");
  MimeMessage mimeMessage2 = sender.createMimeMessage();
  mimeMessage2.setRecipient(Message.RecipientType.TO, new InternetAddress("she@mail.org"));
  try {
    sender.send(mimeMessage1, mimeMessage2);
  }
  catch (MailSendException ex) {
    ex.printStackTrace();
    assertEquals("host", sender.transport.getConnectedHost());
    assertEquals("username", sender.transport.getConnectedUsername());
    assertEquals("password", sender.transport.getConnectedPassword());
    assertTrue(sender.transport.isCloseCalled());
    assertEquals(1, sender.transport.getSentMessages().size());
    assertEquals(mimeMessage2, sender.transport.getSentMessage(0));
    assertEquals(1, ex.getFailedMessages().size());
    assertEquals(mimeMessage1, ex.getFailedMessages().keySet().iterator().next());
    Object subEx = ex.getFailedMessages().values().iterator().next();
    assertTrue(subEx instanceof MessagingException);
    assertEquals("failed", ((MessagingException) subEx).getMessage());
  }
}
origin: camunda/camunda-bpm-platform

  from = ((SMTPMessage)message).getEnvelopeFrom();
if (from == null || from.length() <= 0)
  from = session.getProperty("mail." + name + ".from");
if (from == null || from.length() <= 0) {
  Address[] fa;
  Address me;
  if (message != null && (fa = message.getFrom()) != null &&
    fa.length > 0)
  me = fa[0];
  else
  me = InternetAddress.getLocalAddress(session);
  from = ((InternetAddress)me).getAddress();
  else
  throw new MessagingException(
        "can't determine local email address");
  ret = ((SMTPMessage)message).getDSNRet();
  if (ret == null)
  ret = session.getProperty("mail." + name + ".dsn.ret");
  submitter = ((SMTPMessage)message).getSubmitter();
  if (submitter == null)
  submitter = session.getProperty("mail." + name + ".submitter");
    new InternetAddress(from), cmd,
    retCode, ex.getMessage()));
  } catch (AddressException aex) {
origin: spring-projects/spring-batch

@Test(expected = MailSendException.class)
public void testDefaultErrorHandler() throws Exception {
  MimeMessage foo = new MimeMessage(session);
  MimeMessage bar = new MimeMessage(session);
  MimeMessage[] items = new MimeMessage[] { foo, bar };
  // Spring 4.1 changed the send method to be vargs instead of an array
  if(ReflectionUtils.findMethod(MailSender.class, "send", MimeMessage[].class) != null) {
    mailSender.send(aryEq(items));
  }
  else {
    mailSender.send(items);
  }
  when(mailSender).thenThrow(new MailSendException(Collections.singletonMap((Object)foo, (Exception)new MessagingException("FOO"))));
  writer.write(Arrays.asList(items));
}
origin: spring-projects/spring-framework

@Test
public void failedSimpleMessage() throws MessagingException {
  MockJavaMailSender sender = new MockJavaMailSender();
  sender.setHost("host");
  sender.setUsername("username");
  sender.setPassword("password");
  SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
  simpleMessage1.setTo("he@mail.org");
  simpleMessage1.setSubject("fail");
  SimpleMailMessage simpleMessage2 = new SimpleMailMessage();
  simpleMessage2.setTo("she@mail.org");
  try {
    sender.send(simpleMessage1, simpleMessage2);
  }
  catch (MailSendException ex) {
    ex.printStackTrace();
    assertEquals("host", sender.transport.getConnectedHost());
    assertEquals("username", sender.transport.getConnectedUsername());
    assertEquals("password", sender.transport.getConnectedPassword());
    assertTrue(sender.transport.isCloseCalled());
    assertEquals(1, sender.transport.getSentMessages().size());
    assertEquals(new InternetAddress("she@mail.org"), sender.transport.getSentMessage(0).getAllRecipients()[0]);
    assertEquals(1, ex.getFailedMessages().size());
    assertEquals(simpleMessage1, ex.getFailedMessages().keySet().iterator().next());
    Object subEx = ex.getFailedMessages().values().iterator().next();
    assertTrue(subEx instanceof MessagingException);
    assertEquals("failed", ((MessagingException) subEx).getMessage());
  }
}
origin: camunda/camunda-bpm-platform

/**
 * Sets reply-to address header.
 * @param msg the target message.
 */
private void setReplyTo(final Message msg) {
  final String reply = getSession(msg).getProperty("mail.reply.to");
  if (!isEmpty(reply)) {
    try {
      final Address[] address = InternetAddress.parse(reply, false);
      if (address.length > 0) {
        msg.setReplyTo(address);
      }
    } catch (final MessagingException ME) {
      reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
    }
  }
}
javax.mailMessagingException

Javadoc

The base class for all exceptions thrown by the Messaging classes

Most used methods

  • getMessage
  • <init>
    Constructs a MessagingException with the specified Exception and detail message. The specified excep
  • printStackTrace
  • getNextException
    Get the next exception chained to this one. If the next exception is a MessagingException, the chain
  • toString
    Override toString method to provide information on nested exceptions.
  • setNextException
    Add an exception to the end of the chain. If the end is not a MessagingException, this exception can
  • initCause
  • getCause
    Overrides the getCause method of Throwable to return the next exception in the chain of nested excep
  • superToString
    Return the "toString" information for this exception, without any information on nested exceptions.
  • getLocalizedMessage
  • addSuppressed
  • getStackTrace
  • addSuppressed,
  • getStackTrace,
  • setStackTrace

Popular in Java

  • Running tasks concurrently on multiple threads
  • startActivity (Activity)
  • getApplicationContext (Context)
  • getSystemService (Context)
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now