javax.mail.internet.MimeMessage.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(171)

本文整理了Java中javax.mail.internet.MimeMessage.<init>()方法的一些代码示例,展示了MimeMessage.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MimeMessage.<init>()方法的具体详情如下:
包路径:javax.mail.internet.MimeMessage
类名称:MimeMessage
方法名:<init>

MimeMessage.<init>介绍

[英]Constructs an empty MimeMessage object with the given Folder and message number.

This method is for providers subclassing MimeMessage.
[中]使用给定的文件夹和消息编号构造一个空的mimessage对象。
此方法用于子类化MimeMessage的提供程序。

代码示例

代码示例来源:origin: blynkkk/blynk-server

private void send(String to, String subj, String body, String contentType) throws Exception {
  MimeMessage message = new MimeMessage(session);
  message.setFrom(from);
  message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
  message.setSubject(subj, "UTF-8");
  message.setContent(body, contentType);
  Transport.send(message);
  log.trace("Mail to {} was sent. Subj : {}, body : {}", to, subj, body);
}

代码示例来源:origin: gocd/gocd

public MimeMessage createMessage(String from, String to, String subject, String body)
    throws MessagingException {
  MimeMessage msg = new MimeMessage(session);
  msg.setFrom(new InternetAddress(from));
  msg.setRecipients(TO, to);
  msg.setSubject(subject);
  msg.setContent(msg, "text/plain");
  msg.setSentDate(new Date());
  msg.setText(body);
  msg.setSender(new InternetAddress(from));
  msg.setReplyTo(new InternetAddress[]{new InternetAddress(from)});
  return msg;
}

代码示例来源:origin: JpressProjects/jpress

private Message createMessage() {
  Properties props = new Properties();
  props.setProperty("mail.transport.protocol", "smtp");
  props.setProperty("mail.smtp.auth", "true");
  props.setProperty("mail.smtp.host", host);
  props.setProperty("mail.smtp.port", "25");
  if (useSSL) {
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    props.setProperty("mail.smtp.port", "465");
  }
  // error:javax.mail.MessagingException: 501 Syntax: HELO hostname
  props.setProperty("mail.smtp.localhost", "127.0.0.1");
  Session session = Session.getInstance(props, this);
  Message message = new MimeMessage(session);
  try {
    message.setFrom(new InternetAddress(MimeUtility.encodeText(name) + "<" + name + ">"));
  } catch (Exception e) {
    logger.error(e.getMessage(), e);
  }
  return message;
}

代码示例来源:origin: ltsopensource/light-task-scheduler

public void send(String to, String title, String message) throws Exception {
    Session session = Session.getDefaultInstance(properties, getAuthenticator());
    // Create a default MimeMessage object.
    MimeMessage mimeMessage = new MimeMessage(session);
    // Set From: header field of the header.
    mimeMessage.setFrom(new InternetAddress(adminAddress));
    // Set To: header field of the header.
    mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
    // Set Subject: header field
    mimeMessage.setSubject(title);
    // Now set the actual message
    mimeMessage.setText(message);
    // Send message
    Transport.send(mimeMessage);
  }
}

代码示例来源:origin: pentaho/pentaho-kettle

Message msg = new MimeMessage( session );
InternetAddress addressFrom = new InternetAddress( (String) ArgList[1] );
msg.setFrom( addressFrom );
 addressTo[i] = new InternetAddress( strArrRecipients[i] );

代码示例来源:origin: blynkkk/blynk-server

private void send(String to, String subj, String body, String contentType) throws Exception {
  MimeMessage message = new MimeMessage(session);
  message.setFrom(from);
  message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
  message.setSubject(subj, "UTF-8");
  message.setContent(body, contentType);
  try (Transport transport = session.getTransport()) {
    transport.connect(host, username, password);
    transport.sendMessage(message, message.getAllRecipients());
  }
  log.debug("Mail sent to {}. Subj: {}", to, subj);
  log.trace("Mail body: {}", body);
}

代码示例来源:origin: ltsopensource/light-task-scheduler

public void send(String to, String title, String message) throws Exception {
    Session session = Session.getDefaultInstance(properties, getAuthenticator());
    // Create a default MimeMessage object.
    MimeMessage mimeMessage = new MimeMessage(session);
    // Set From: header field of the header.
    mimeMessage.setFrom(new InternetAddress(adminAddress));
    // Set To: header field of the header.
    mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
    // Set Subject: header field
    mimeMessage.setSubject(title);
    // Now set the actual message
    mimeMessage.setText(message);
    // Send message
    Transport.send(mimeMessage);
  }
}

代码示例来源:origin: javaee-samples/javaee7-samples

+ "\"...<br>");
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(creds.getFrom()));
message.setRecipients(Message.RecipientType.TO,
  InternetAddress.parse(creds.getTo()));

代码示例来源:origin: blynkkk/blynk-server

@Override
public void sendHtmlWithAttachment(String to, String subj, String body,
                  QrHolder[] attachmentData) throws Exception {
  MimeMessage message = new MimeMessage(session);
  message.setFrom(from);
  message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
  message.setSubject(subj, "UTF-8");
  Multipart multipart = new MimeMultipart();
  MimeBodyPart bodyMessagePart = new MimeBodyPart();
  bodyMessagePart.setContent(body, TEXT_HTML_CHARSET_UTF_8);
  multipart.addBodyPart(bodyMessagePart);
  attachQRs(multipart, attachmentData);
  attachCSV(multipart, attachmentData);
  message.setContent(multipart);
  Transport.send(message);
  log.trace("Mail to {} was sent. Subj : {}, body : {}", to, subj, body);
}

代码示例来源:origin: stagemonitor/stagemonitor

/**
 * Creates a MimeMessage containing given Multipart.
 * Subject, sender and content and session will be set.
 * @param session current mail session
 * @return MimeMessage without recipients
 * @throws MessagingException
 */
public MimeMessage createMimeMessage(Session session) throws MessagingException {
  if (isEmpty(htmlPart) && isEmpty(textPart)) {
    throw new IllegalArgumentException("Missing email content");
  }
  final MimeMessage msg = new MimeMessage(session);
  msg.setSubject(subject);
  msg.setFrom(new InternetAddress(from));
  msg.setContent(createMultiPart());
  msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients, false));
  return msg;
}

代码示例来源:origin: javaee-samples/javaee7-samples

+ "\"...<br>");
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(creds.getFrom()));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(creds.getTo()));
message.setSubject("Sending message using Annotated JavaMail "

代码示例来源:origin: blynkkk/blynk-server

@Override
public void sendHtmlWithAttachment(String to, String subj, String body, QrHolder[] attachments) throws Exception {
  MimeMessage message = new MimeMessage(session);
  message.setFrom(from);
  message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
  message.setSubject(subj, "UTF-8");
  Multipart multipart = new MimeMultipart();
  MimeBodyPart bodyMessagePart = new MimeBodyPart();
  bodyMessagePart.setContent(body, TEXT_HTML_CHARSET_UTF_8);
  multipart.addBodyPart(bodyMessagePart);
  for (QrHolder qrHolder : attachments) {
    MimeBodyPart attachmentsPart = new MimeBodyPart();
    attachmentsPart.setDataHandler(new DataHandler(new ByteArrayDataSource(qrHolder.data, "image/jpeg")));
    attachmentsPart.setFileName(qrHolder.makeQRFilename());
    multipart.addBodyPart(attachmentsPart);
  }
  message.setContent(multipart);
  try (Transport transport = session.getTransport()) {
    transport.connect(host, username, password);
    transport.sendMessage(message, message.getAllRecipients());
  }
  log.debug("Mail sent to {}. Subj: {}", to, subj);
  log.trace("Mail body: {}", body);
}

代码示例来源:origin: quartz-scheduler/quartz

protected MimeMessage prepareMimeMessage(MailInfo mailInfo)
  throws MessagingException {
  Session session = getMailSession(mailInfo);
  MimeMessage mimeMessage = new MimeMessage(session);
  Address[] toAddresses = InternetAddress.parse(mailInfo.getTo());
  mimeMessage.setRecipients(Message.RecipientType.TO, toAddresses);
  if (mailInfo.getCc() != null) {
    Address[] ccAddresses = InternetAddress.parse(mailInfo.getCc());
    mimeMessage.setRecipients(Message.RecipientType.CC, ccAddresses);
  }
  mimeMessage.setFrom(new InternetAddress(mailInfo.getFrom()));
  
  if (mailInfo.getReplyTo() != null) {
    mimeMessage.setReplyTo(new InternetAddress[]{new InternetAddress(mailInfo.getReplyTo())});
  }
  
  mimeMessage.setSubject(mailInfo.getSubject());
  
  mimeMessage.setSentDate(new Date());
  setMimeMessageContent(mimeMessage, mailInfo);
  return mimeMessage;
}

代码示例来源:origin: pentaho/pentaho-kettle

Message msg = new MimeMessage( session );
InternetAddress addressFrom = new InternetAddress( (String) ArgList[1] );
msg.setFrom( addressFrom );
 addressTo[i] = new InternetAddress( strArrRecipients[i] );

代码示例来源:origin: looly/hutool

final MimeMessage msg = new MimeMessage(getSession(this.useGlobalSession));
msg.setSubject(this.title, charset.name());

代码示例来源:origin: networknt/light-4j

/**
 * Send email with a string content.
 *
 * @param to destination email address
 * @param subject email subject
 * @param content email content
 * @throws MessagingException message exception
 */
public void sendMail (String to, String subject, String content) throws MessagingException {
  Properties props = new Properties();
  props.put("mail.smtp.user", emailConfg.getUser());
  props.put("mail.smtp.host", emailConfg.getHost());
  props.put("mail.smtp.port", emailConfg.getPort());
  props.put("mail.smtp.starttls.enable","true");
  props.put("mail.smtp.debug", emailConfg.getDebug());
  props.put("mail.smtp.auth", emailConfg.getAuth());
  props.put("mail.smtp.ssl.trust", emailConfg.host);
  SMTPAuthenticator auth = new SMTPAuthenticator(emailConfg.getUser(), (String)secret.get(SecretConstants.EMAIL_PASSWORD));
  Session session = Session.getInstance(props, auth);
  MimeMessage message = new MimeMessage(session);
  message.setFrom(new InternetAddress(emailConfg.getUser()));
  message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
  message.setSubject(subject);
  message.setContent(content, "text/html");
  // Send message
  Transport.send(message);
  if(logger.isInfoEnabled()) logger.info("An email has been sent to " + to + " with subject " + subject);
}

代码示例来源:origin: pentaho/pentaho-kettle

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: looly/hutool

final MimeMessage msg = new MimeMessage(getSession(this.useGlobalSession));
msg.setSubject(this.title, charset.name());

代码示例来源:origin: apache/geode

MimeMessage mimeMessage = new MimeMessage(session);
String subject = emailData.subject;
String message = emailData.message;
  mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(mailToAddresses[i]));
  subject = "Alert from GemFire Admin Agent";
 mimeMessage.setSubject(subject);

代码示例来源:origin: kiegroup/jbpm

EmailNotificationHeader header = headers.get(lang);
Message msg = new MimeMessage(mailSession);
Set<String> toAddresses = new HashSet<String>();
for (User user : entry.getValue()) {
  User user = TaskModelProvider.getFactory().newUser();
  ((InternalOrganizationalEntity) user).setId(header.getFrom());
  msg.setFrom( new InternetAddress(userInfo.getEmailForEntity(user)));
} else {
  msg.setFrom( new InternetAddress(mailSession.getProperty("mail.from")));
  ((InternalOrganizationalEntity) user).setId(header.getReplyTo());
  msg.setReplyTo( new InternetAddress[] {  
      new InternetAddress(userInfo.getEmailForEntity(user))});
} else if (mailSession.getProperty("mail.replyto") != null) {
  msg.setReplyTo( new InternetAddress[] {  new InternetAddress(mailSession.getProperty("mail.replyto"))});

相关文章

MimeMessage类方法