本文整理汇总了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;
}
示例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 );
}
}
}