當前位置: 首頁>>代碼示例>>Java>>正文


Java Message.setHeader方法代碼示例

本文整理匯總了Java中javax.mail.Message.setHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java Message.setHeader方法的具體用法?Java Message.setHeader怎麽用?Java Message.setHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.mail.Message的用法示例。


在下文中一共展示了Message.setHeader方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: _setupMessage

import javax.mail.Message; //導入方法依賴的package包/類
/**
 * Set up a new message.
 */
private Message _setupMessage(Message msg)
{
  try
  {
    String username = _account.getUsername();
    String from = username + "@" + _account.getDomain();
    List<InternetAddress> to = _getEmailList(getTo());
    
    List<InternetAddress> cc = null;
    String ccString = getCc();
    if(ccString != null) 
    {
      cc = _getEmailList(ccString);  
    }
    
    msg.setFrom(new InternetAddress(from));
    if ((to != null) && !to.isEmpty())
      msg.setRecipients(Message.RecipientType.TO,
                        to.toArray(new InternetAddress[0]));

    if ((cc != null) && !cc.isEmpty())
      msg.setRecipients(Message.RecipientType.CC,
                        cc.toArray(new InternetAddress[0]));
    msg.setSubject(_subject == null ? "" : _subject);
    if ((_attachment1 == null) &&
        (_attachment2 == null) &&
        (_attachment3 == null))
    {
      msg.setText(_content == null ? "" : _content);
    }
    // Multipart.
    else
    {
      // Create the message part
      BodyPart messageBodyPart = new MimeBodyPart();

      // Fill the message
      messageBodyPart.setText(_content == null ? "" : _content);

      Multipart multipart = new MimeMultipart();
      multipart.addBodyPart(messageBodyPart);

      if (_attachment1 != null)
        _addAttachment(multipart, _attachment1);
      if (_attachment2 != null)
        _addAttachment(multipart, _attachment2);
      if (_attachment3 != null)
        _addAttachment(multipart, _attachment3);

      // Put all the parts in the message
      msg.setContent(multipart);
    }

    String mailer = "OracleAdfEmailDemo";
    msg.setHeader("X-Mailer", mailer);
    msg.setSentDate(new Date());

    return msg;
  }
  catch(AddressException ae)
  {
     _showSendException(ae);
  }
  catch(MessagingException me)
  {
    _showSendException(me);
  }
  catch(Exception e)
  {
    _showSendException(e);
  }

  return null;
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:78,代碼來源:NewMessageBackingBean.java

示例2: send

import javax.mail.Message; //導入方法依賴的package包/類
public void send ( final String subject, final String text ) throws MessagingException
{
    final Message message = new MimeMessage ( this.session );

    if ( this.from != null )
    {
        message.setFrom ( this.from );
    }
    else
    {
        message.setFrom ();
    }

    message.setHeader ( "Return-Path", "<>" );

    message.setRecipients ( javax.mail.Message.RecipientType.TO, this.to );
    message.setSubject ( subject );
    message.setText ( text );

    message.saveChanges ();

    final Transport transport = this.session.getTransport ();
    logger.debug ( "Connecting transport..." );
    transport.connect ();
    logger.debug ( "Connecting transport... done!" );
    try
    {
        logger.debug ( "Sending message..." );
        transport.sendMessage ( message, message.getAllRecipients () );
        logger.debug ( "Sending message... done!" );
    }
    finally
    {
        logger.debug ( "Closing transport..." );
        try
        {
            transport.close ();
            logger.debug ( "Closing transport... done!" );
        }
        catch ( final Exception e )
        {
            logger.info ( "Failed to close transport", e );
        }
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:46,代碼來源:MailSender.java


注:本文中的javax.mail.Message.setHeader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。