本文整理了Java中javax.mail.internet.MimeMessage.setRecipient()
方法的一些代码示例,展示了MimeMessage.setRecipient()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MimeMessage.setRecipient()
方法的具体详情如下:
包路径:javax.mail.internet.MimeMessage
类名称:MimeMessage
方法名:setRecipient
[英]Set the specified recipient type to the given addresses. If the address parameter is null
, the corresponding recipient field is removed.
[中]将指定的收件人类型设置为给定的地址。如果地址参数为null
,则相应的收件人字段将被删除。
代码示例来源:origin: spring-projects/spring-framework
public void setTo(InternetAddress to) throws MessagingException {
Assert.notNull(to, "To address must not be null");
validateAddress(to);
this.mimeMessage.setRecipient(Message.RecipientType.TO, to);
}
代码示例来源:origin: stackoverflow.com
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
else
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
Transport.send(message);
}catch(Exception e){
代码示例来源:origin: stackoverflow.com
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
else
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
smtpTransport.sendMessage(message, message.getAllRecipients());
代码示例来源:origin: spring-projects/spring-framework
public void setCc(InternetAddress cc) throws MessagingException {
Assert.notNull(cc, "Cc address must not be null");
validateAddress(cc);
this.mimeMessage.setRecipient(Message.RecipientType.CC, cc);
}
代码示例来源:origin: spring-projects/spring-framework
public void setBcc(InternetAddress bcc) throws MessagingException {
Assert.notNull(bcc, "Bcc address must not be null");
validateAddress(bcc);
this.mimeMessage.setRecipient(Message.RecipientType.BCC, bcc);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void prepare(MimeMessage mimeMessage) throws MessagingException {
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("you@mail.org"));
messages.add(mimeMessage);
}
};
代码示例来源:origin: spring-projects/spring-framework
@Override
public void prepare(MimeMessage mimeMessage) throws MessagingException {
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("he@mail.org"));
messages.add(mimeMessage);
}
};
代码示例来源:origin: spring-projects/spring-framework
@Override
public void prepare(MimeMessage mimeMessage) throws MessagingException {
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("she@mail.org"));
messages.add(mimeMessage);
}
};
代码示例来源:origin: org.springframework/spring-context-support
public void setBcc(InternetAddress bcc) throws MessagingException {
Assert.notNull(bcc, "Bcc address must not be null");
validateAddress(bcc);
this.mimeMessage.setRecipient(Message.RecipientType.BCC, bcc);
}
代码示例来源:origin: org.springframework/spring-context-support
public void setCc(InternetAddress cc) throws MessagingException {
Assert.notNull(cc, "Cc address must not be null");
validateAddress(cc);
this.mimeMessage.setRecipient(Message.RecipientType.CC, cc);
}
代码示例来源:origin: org.springframework/spring-context-support
public void setTo(InternetAddress to) throws MessagingException {
Assert.notNull(to, "To address must not be null");
validateAddress(to);
this.mimeMessage.setRecipient(Message.RecipientType.TO, to);
}
代码示例来源:origin: shopizer-ecommerce/shopizer
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
代码示例来源:origin: igniterealtime/Openfire
message.setHeader("Date", format.format(new Date()));
message.setHeader("Content-Transfer-Encoding", "8bit");
message.setRecipient(Message.RecipientType.TO, to);
message.setFrom(from);
message.setSubject(StringUtils.replace(subject, "\n", ""), encoding);
代码示例来源:origin: spring-projects/spring-framework
@Test
public void javaMailSenderWithCustomSession() throws MessagingException {
final Session session = Session.getInstance(new Properties());
MockJavaMailSender sender = new MockJavaMailSender() {
@Override
protected Transport getTransport(Session sess) throws NoSuchProviderException {
assertEquals(session, sess);
return super.getTransport(sess);
}
};
sender.setSession(session);
sender.setHost("host");
sender.setUsername("username");
sender.setPassword("password");
MimeMessage mimeMessage = sender.createMimeMessage();
mimeMessage.setSubject("custom");
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("you@mail.org"));
mimeMessage.setSentDate(new GregorianCalendar(2005, 3, 1).getTime());
sender.send(mimeMessage);
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(mimeMessage, sender.transport.getSentMessage(0));
}
代码示例来源: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: spring-projects/spring-framework
@Test
public void javaMailSenderWithMimeMessages() 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"));
MimeMessage mimeMessage2 = sender.createMimeMessage();
mimeMessage2.setRecipient(Message.RecipientType.TO, new InternetAddress("she@mail.org"));
sender.send(mimeMessage1, mimeMessage2);
assertEquals("host", sender.transport.getConnectedHost());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertEquals(2, sender.transport.getSentMessages().size());
assertEquals(mimeMessage1, sender.transport.getSentMessage(0));
assertEquals(mimeMessage2, sender.transport.getSentMessage(1));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void javaMailProperties() throws MessagingException {
Properties props = new Properties();
props.setProperty("bogusKey", "bogusValue");
MockJavaMailSender sender = new MockJavaMailSender() {
@Override
protected Transport getTransport(Session sess) throws NoSuchProviderException {
assertEquals("bogusValue", sess.getProperty("bogusKey"));
return super.getTransport(sess);
}
};
sender.setJavaMailProperties(props);
sender.setHost("host");
sender.setUsername("username");
sender.setPassword("password");
MimeMessage mimeMessage = sender.createMimeMessage();
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("you@mail.org"));
sender.send(mimeMessage);
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(mimeMessage, sender.transport.getSentMessage(0));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void javaMailSenderWithMimeMessage() throws MessagingException {
MockJavaMailSender sender = new MockJavaMailSender();
sender.setHost("host");
sender.setUsername("username");
sender.setPassword("password");
MimeMessage mimeMessage = sender.createMimeMessage();
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("you@mail.org"));
sender.send(mimeMessage);
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(mimeMessage, sender.transport.getSentMessage(0));
}
代码示例来源:origin: bill1012/AdminEAP
/**
* 发送邮件
*
* @param recipient 收件人邮箱地址
* @param subject 邮件主题
* @param content 邮件内容
* @throws AddressException
* @throws MessagingException
*/
public void send(String recipient, String subject, Object content)
throws AddressException, MessagingException {
// 创建mime类型邮件
final MimeMessage message = new MimeMessage(session);
// 设置发信人
message.setFrom(new InternetAddress(authenticator.getUsername()));
// 设置收件人
message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(recipient));
// 设置主题
message.setSubject(subject);
message.setSentDate(new Date());
// 设置邮件内容
message.setContent(content.toString(), "text/html;charset=utf-8");
// 发送
Transport.send(message);
}
代码示例来源:origin: 0opslab/opslabJutil
message.setRecipient(Message.RecipientType.TO, to);//还可以有CC、BCC
内容来源于网络,如有侵权,请联系作者删除!