本文整理汇总了Java中javax.mail.internet.MimeMessage.RecipientType类的典型用法代码示例。如果您正苦于以下问题:Java RecipientType类的具体用法?Java RecipientType怎么用?Java RecipientType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RecipientType类属于javax.mail.internet.MimeMessage包,在下文中一共展示了RecipientType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSendingToCarbonCopy
import javax.mail.internet.MimeMessage.RecipientType; //导入依赖的package包/类
/**
* Test for CC / BCC
* @throws Exception
*/
@Test
public void testSendingToCarbonCopy() throws IOException, MessagingException
{
// PARAM_TO variant
Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME);
mailAction.setParameterValue(MailActionExecuter.PARAM_FROM, "[email protected]");
mailAction.setParameterValue(MailActionExecuter.PARAM_TO, "[email protected]");
mailAction.setParameterValue(MailActionExecuter.PARAM_CC, "[email protected]");
mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Testing CARBON COPY");
mailAction.setParameterValue(MailActionExecuter.PARAM_TEMPLATE, "alfresco/templates/mail/test.txt.ftl");
mailAction.setParameterValue(MailActionExecuter.PARAM_TEMPLATE_MODEL, (Serializable) getModel());
ACTION_SERVICE.executeAction(mailAction, null);
MimeMessage message = ACTION_EXECUTER.retrieveLastTestMessage();
Assert.assertNotNull(message);
Address[] all = message.getAllRecipients();
Address[] ccs = message.getRecipients(RecipientType.CC);
Assert.assertEquals("recipents too short", 2, all.length);
Assert.assertEquals("cc too short", 1, ccs.length);
Assert.assertTrue(ccs[0].toString().contains("some.carbon"));
}
示例2: main
import javax.mail.internet.MimeMessage.RecipientType; //导入依赖的package包/类
public static void main(String[] args) throws AddressException,
MessagingException {
Properties props = new Properties();
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.transport.protocol", "smtp");
Session session = Session.getInstance(props, new Authenticator() {
String userName = "[email protected]";
String password = "123456";
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(userName, password);
}
});
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("[email protected]"));
msg.setSubject("中文主题");
msg.setContent("<span style=\"color:red\">中文呵呵呵</span>",
"text/html;charset=utf-8");
msg.setRecipients(RecipientType.TO, InternetAddress
.parse("[email protected]," + "[email protected]"));
Transport.send(msg);
}
示例3: testSendingToCarbonCopy
import javax.mail.internet.MimeMessage.RecipientType; //导入依赖的package包/类
/**
* Test for CC / BCC
* @throws Exception
*/
@Test
public void testSendingToCarbonCopy() throws IOException, MessagingException
{
// PARAM_TO variant
Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME);
mailAction.setParameterValue(MailActionExecuter.PARAM_FROM, "[email protected]");
mailAction.setParameterValue(MailActionExecuter.PARAM_TO, "[email protected]");
mailAction.setParameterValue(MailActionExecuter.PARAM_CC, "[email protected]");
mailAction.setParameterValue(MailActionExecuter.PARAM_BCC, "[email protected]");
mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Testing CARBON COPY");
mailAction.setParameterValue(MailActionExecuter.PARAM_TEMPLATE, "alfresco/templates/mail/test.txt.ftl");
mailAction.setParameterValue(MailActionExecuter.PARAM_TEMPLATE_MODEL, (Serializable) getModel());
ACTION_SERVICE.executeAction(mailAction, null);
MimeMessage message = ACTION_EXECUTER.retrieveLastTestMessage();
Assert.assertNotNull(message);
Address[] all = message.getAllRecipients();
Address[] ccs = message.getRecipients(RecipientType.CC);
Address[] bccs = message.getRecipients(RecipientType.BCC);
Assert.assertEquals(3, all.length);
Assert.assertEquals(1, ccs.length);
Assert.assertEquals(1, bccs.length);
Assert.assertTrue(ccs[0].toString().contains("some.carbon"));
Assert.assertTrue(bccs[0].toString().contains("some.blindcarbon"));
}
示例4: testSendingToArrayOfCarbonCopyAndBlindCarbonCopyUsers
import javax.mail.internet.MimeMessage.RecipientType; //导入依赖的package包/类
/**
* ALF-21948
*/
@Test
public void testSendingToArrayOfCarbonCopyAndBlindCarbonCopyUsers() throws MessagingException
{
Map<String, Serializable> params = new HashMap<String, Serializable>();
String[] ccArray = { "[email protected]", "[email protected]" };
String[] bccArray = { "[email protected]", "[email protected]", "[email protected]" };
params.put(MailActionExecuter.PARAM_FROM, "[email protected]");
params.put(MailActionExecuter.PARAM_TO, "[email protected]");
params.put(MailActionExecuter.PARAM_CC, ccArray);
params.put(MailActionExecuter.PARAM_BCC, bccArray);
params.put(MailActionExecuter.PARAM_TEXT, "Mail body here");
params.put(MailActionExecuter.PARAM_SUBJECT, "Subject text");
Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME, params);
ACTION_EXECUTER.resetTestSentCount();
ACTION_SERVICE.executeAction(mailAction, null);
MimeMessage message = ACTION_EXECUTER.retrieveLastTestMessage();
Assert.assertNotNull(message);
Address[] all = message.getAllRecipients();
Address[] ccs = message.getRecipients(RecipientType.CC);
Address[] bccs = message.getRecipients(RecipientType.BCC);
Assert.assertEquals(6, all.length);
Assert.assertEquals(2, ccs.length);
Assert.assertEquals(3, bccs.length);
Assert.assertTrue(ccs[0].toString().contains("cc_user1") && ccs[1].toString().contains("cc_user2"));
Assert.assertTrue(bccs[0].toString().contains("bcc_user3") && bccs[1].toString().contains("bcc_user4")
&& bccs[2].toString().contains("bcc_user5"));
}
示例5: testSendingToListOfCarbonCopyAndBlindCarbonCopyUsers
import javax.mail.internet.MimeMessage.RecipientType; //导入依赖的package包/类
/**
* ALF-21948
*/
@Test
public void testSendingToListOfCarbonCopyAndBlindCarbonCopyUsers() throws MessagingException
{
List<String> ccList = new ArrayList<String>();
ccList.add("[email protected]");
ccList.add("[email protected]");
List<String> bccList = new ArrayList<String>();
bccList.add("[email protected]");
bccList.add("[email protected]");
bccList.add("[email protected]");
Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME);
mailAction.setParameterValue(MailActionExecuter.PARAM_FROM, "[email protected]");
mailAction.setParameterValue(MailActionExecuter.PARAM_TO, "[email protected]");
mailAction.setParameterValue(MailActionExecuter.PARAM_CC, (Serializable) ccList);
mailAction.setParameterValue(MailActionExecuter.PARAM_BCC, (Serializable) bccList);
mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Testing (BLIND) CARBON COPY");
mailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, "mail body here");
ACTION_EXECUTER.resetTestSentCount();
ACTION_SERVICE.executeAction(mailAction, null);
MimeMessage message = ACTION_EXECUTER.retrieveLastTestMessage();
Assert.assertNotNull(message);
Address[] all = message.getAllRecipients();
Address[] ccs = message.getRecipients(RecipientType.CC);
Address[] bccs = message.getRecipients(RecipientType.BCC);
Assert.assertEquals(6, all.length);
Assert.assertEquals(2, ccs.length);
Assert.assertEquals(3, bccs.length);
Assert.assertTrue(ccs[0].toString().contains("cc_user1") && ccs[1].toString().contains("cc_user2"));
Assert.assertTrue(bccs[0].toString().contains("bcc_user3") && bccs[1].toString().contains("bcc_user4")
&& bccs[2].toString().contains("bcc_user5"));
}
示例6: testComposeMessage_addRecipientsFails
import javax.mail.internet.MimeMessage.RecipientType; //导入依赖的package包/类
@Test(expected = APPlatformException.class)
public void testComposeMessage_addRecipientsFails() throws Exception {
// given
MimeMessage mockMessage = mock(MimeMessage.class);
doThrow(new MessagingException("Adding recipient addresses fails."))
.when(mockMessage).addRecipients(any(RecipientType.class),
any(Address[].class));
doReturn(mockMessage).when(commService).getMimeMessage(
any(Session.class));
// when
commService
.composeMessage(Collections.singletonList("[email protected]"),
"subject", "text");
}
示例7: createMessage
import javax.mail.internet.MimeMessage.RecipientType; //导入依赖的package包/类
/**
* 验证Session,进行发送信息
*/
private static void createMessage(Session session){
Message message = new MimeMessage(session);// 2, 创建代表邮件的对象Message
try {
message.setFrom(new InternetAddress(username));// 设置发件人
message.addRecipient(RecipientType.TO, new InternetAddress(Receiver)); // 设置收件人
message.setSubject(title);// 设置标题
message.setSentDate(new Date());// 设置发送时间
// 设置正文(有链接选择text/html;charset=utf-8)
message.setContent(contents, "text/html;charset=utf-8");
Transport.send(message);// 3,发送邮件Transport
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: fill
import javax.mail.internet.MimeMessage.RecipientType; //导入依赖的package包/类
public void fill(MimeMessage message) throws EmailException {
try {
message.setFrom(from());
message.setRecipients(RecipientType.TO, to().toArray(new Address[0]));
message.setRecipients(RecipientType.CC, cc().toArray(new Address[0]));
message.setRecipients(RecipientType.BCC, bcc().toArray(new Address[0]));
message.setSubject(subject());
message.setContent(content(), contentType());
} catch (MessagingException exception) {
LOGGER.error("Fill mime message", exception);
throw new EmailException(exception);
}
}
示例9: onCreateBestellung
import javax.mail.internet.MimeMessage.RecipientType; //导入依赖的package包/类
public void onCreateBestellung(@Observes @NeueBestellung Bestellung bestellung) {
final Kunde kunde = bestellung.getKunde();
final String empfaengerMail = kunde.getEmail();
if (absenderMail == null || empfaengerMail == null) {
return;
}
final String vorname = kunde.getVorname() == null ? "" : kunde.getVorname();
final String empfaengerName = vorname + " " + kunde.getName();
final MimeMessage message = new MimeMessage(session);
try {
final InternetAddress absenderObj = new InternetAddress(absenderMail, absenderName);
message.setFrom(absenderObj);
// Empfaenger setzen
final InternetAddress empfaenger = new InternetAddress(empfaengerMail, empfaengerName);
message.setRecipient(RecipientType.TO, empfaenger);
// Subject setzen
message.setSubject("Neue Bestellung Nr. " + bestellung.getID());
// Text setzen mit MIME Type "text/plain"
final StringBuilder sb = new StringBuilder(256);
sb.append("<h3>Neue Bestellung Nr. <b>" + bestellung.getID() + "</b></h3>" + NEWLINE);
for (Position p : bestellung.getPositionen()) {
sb.append(p.getAnzahl() + "\t" + p.getArtikel().getBezeichnung() + "<br/>" + NEWLINE);
}
final String text = sb.toString();
LOGGER.trace(text);
message.setContent(text, "text/html;charset=iso-8859-1");
Transport.send(message);
}
catch (MessagingException | UnsupportedEncodingException e) {
LOGGER.error(e.getMessage());
return;
}
}
示例10: sendMail
import javax.mail.internet.MimeMessage.RecipientType; //导入依赖的package包/类
public void sendMail(String recipient, String subject, String text) {
final Email email = new Email();
email.setFromAddress("Oregami", "[email protected]");
email.setSubject(subject);
email.addRecipient(recipient, recipient, RecipientType.TO);
email.setText(text);
new Mailer(mailConfiguration.getHost(), Integer.parseInt(mailConfiguration.getPort()), mailConfiguration.getUsername(), mailConfiguration.getPassword()).sendMail(email);
}
示例11: testPrepareEmailForDisabledUsers
import javax.mail.internet.MimeMessage.RecipientType; //导入依赖的package包/类
@Test
public void testPrepareEmailForDisabledUsers() throws MessagingException
{
String groupName = null;
final String USER1 = "test_user1";
final String USER2 = "test_user2";
try
{
createUser(USER1, null);
NodeRef userNode = createUser(USER2, null);
groupName = AUTHORITY_SERVICE.createAuthority(AuthorityType.GROUP, "testgroup1");
AUTHORITY_SERVICE.addAuthority(groupName, USER1);
AUTHORITY_SERVICE.addAuthority(groupName, USER2);
NODE_SERVICE.addAspect(userNode, ContentModel.ASPECT_PERSON_DISABLED, null);
final Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME);
mailAction.setParameterValue(MailActionExecuter.PARAM_FROM, "[email protected]");
mailAction.setParameterValue(MailActionExecuter.PARAM_TO_MANY, groupName);
mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Testing");
mailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, "Testing");
RetryingTransactionHelper txHelper = APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
MimeMessage mm = txHelper.doInTransaction(new RetryingTransactionCallback<MimeMessage>()
{
@Override
public MimeMessage execute() throws Throwable
{
return ACTION_EXECUTER.prepareEmail(mailAction, null, null, null).getMimeMessage();
}
}, true);
Address[] addresses = mm.getRecipients(Message.RecipientType.TO);
Assert.assertEquals(1, addresses.length);
Assert.assertEquals(USER1 + "@email.com", addresses[0].toString());
}
finally
{
if (groupName != null)
{
AUTHORITY_SERVICE.deleteAuthority(groupName, true);
}
PERSON_SERVICE.deletePerson(USER1);
PERSON_SERVICE.deletePerson(USER2);
}
}
示例12: sendEmail
import javax.mail.internet.MimeMessage.RecipientType; //导入依赖的package包/类
/**
* 用来发送邮件
*
* @param session 与发送邮件的主机的连接(会话)
* @param email 写好的邮件
* @throws Exception 出现异常
*/
public static void sendEmail(Session session, Email email) throws Exception {
// 获取发送邮件的信息类
MimeMessage message = new MimeMessage(session);
// 设置发送方邮件地址
message.setFrom(new InternetAddress(email.getFrom()));
// 设置发送类型和被发送方的邮件地址
if (!email.getTo().isEmpty()) {
message.setRecipients(RecipientType.TO, email.getTo());
}
if (!email.getCc().isEmpty()) {
message.setRecipients(RecipientType.CC, email.getCc());
}
if (!email.getBcc().isEmpty()) {
message.setRecipients(RecipientType.BCC, email.getBcc());
}
// 设置邮件主题
message.setSubject(email.getSubject(), "utf-8");
// 设置邮件内容
MimeMultipart content = new MimeMultipart();
// 邮件正文
MimeBodyPart text = new MimeBodyPart();
text.setContent(email.getContent(), email.getType());
content.addBodyPart(text);
// 设置附件
if (email.getAttachments() != null) {
for (AttachmentBean attachment : email.getAttachments()) {
MimeBodyPart part = new MimeBodyPart();
part.attachFile(attachment.getFile());
part.setFileName(MimeUtility.encodeText(attachment
.getFileName()));
if (attachment.getCid() != null) {
part.setContentID(attachment.getCid());
}
content.addBodyPart(part);
}
}
// 将邮件内容添加到信息中
message.setContent(content);
// 发送邮件
Transport.send(message);
}
示例13: testPrepareEmailForDisabledUsers
import javax.mail.internet.MimeMessage.RecipientType; //导入依赖的package包/类
@Test
public void testPrepareEmailForDisabledUsers() throws MessagingException
{
String groupName = null;
final String USER1 = "test_user1";
final String USER2 = "test_user2";
try
{
createUser(USER1, null);
NodeRef userNode = createUser(USER2, null);
groupName = AUTHORITY_SERVICE.createAuthority(AuthorityType.GROUP, "testgroup1");
AUTHORITY_SERVICE.addAuthority(groupName, USER1);
AUTHORITY_SERVICE.addAuthority(groupName, USER2);
NODE_SERVICE.addAspect(userNode, ContentModel.ASPECT_PERSON_DISABLED, null);
final Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME);
mailAction.setParameterValue(MailActionExecuter.PARAM_FROM, "[email protected]");
mailAction.setParameterValue(MailActionExecuter.PARAM_TO_MANY, groupName);
mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Testing");
mailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, "Testing");
RetryingTransactionHelper txHelper = APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
MimeMessage mm = txHelper.doInTransaction(new RetryingTransactionCallback<MimeMessage>()
{
@Override
public MimeMessage execute() throws Throwable
{
return ACTION_EXECUTER.prepareEmail(mailAction, null, null, null).getMimeMessage();
}
}, true);
Address[] addresses = mm.getRecipients(Message.RecipientType.TO);
Assert.assertEquals(1, addresses.length);
Assert.assertEquals(USER1 + "@email.com", addresses[0].toString());
}
finally
{
if (groupName != null)
{
AUTHORITY_SERVICE.deleteAuthority(groupName, true);
}
PERSON_SERVICE.deletePerson(USER1);
PERSON_SERVICE.deletePerson(USER2);
}
}
示例14: email
import javax.mail.internet.MimeMessage.RecipientType; //导入依赖的package包/类
public void email(String text, TregminePlayer p){
final String username = tregmine.getConfig().getString("support.user");
final String password = tregmine.getConfig().getString("support.password");
final List<?> to = tregmine.getConfig().getList("support.to");
String[] recipients = to.toArray(new String[to.size()]);
String time = String.format("[%tm/%td/%ty - %tH:%tM:%tS] ",
new Date(), new Date(),new Date(),new Date(),new Date(),new Date());
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username,password);
}
});
try {
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
Message message = new MimeMessage(session);
message.setRecipients(RecipientType.TO, addressTo);
message.setSubject("[Help Request] from " + p.getName());
message.setText(
"Help request from: " + p.getName() + " at " + time + "\n" +
"\n" +
"Message: " + text + "\n"
);
Transport.send(message);
p.sendMessage(ChatColor.GREEN + "Help request sent, we will get back to you ASAP :)");
} catch (MessagingException e) {
p.sendMessage(ChatColor.RED + "Error sending message, please try again.");
throw new RuntimeException(e);
}
}
示例15: to
import javax.mail.internet.MimeMessage.RecipientType; //导入依赖的package包/类
/**
* Make assertions on the sender of the message(s) using fluent API.
*
* <pre>
* .receivedMessages().message(0).to()
* .address(hasItems("[email protected]", "[email protected]"))
* .personal(hasItems("Foo", "Bar"))
* </pre>
*
* Will check if the list of email addresses of direct recipients (TO) of
* the first message are exactly "[email protected]", "[email protected]"
* and the list of displayed address of direct recipients (TO) of the first
* message are exactly "Foo", "Bar".
*
* <pre>
* .receivedMessages().forEach().to()
* .address(hasItems("[email protected]", "[email protected]"))
* .personal(hasItems("Foo", "Bar"))
* </pre>
*
* Will check if the list of email addresses of direct recipients (TO) of
* every message are exactly "[email protected]", "[email protected]" and
* the list of displayed address of direct recipients (TO) of every message
* are exactly "Foo", "Bar".
*
* @return the fluent API for chaining assertions on received message(s)
*/
public AddressListAssert<EmailAssert<P>> to() {
try {
int index = 0;
List<AddressesWithContext> addresses = new ArrayList<>();
for (Message message : actual) {
addresses.add(new AddressesWithContext(asList((InternetAddress[]) message.getRecipients(RecipientType.TO)), "to", new SingleMessageContext(index++)));
}
return new AddressListAssert<>(addresses, this);
} catch (MessagingException e) {
throw new AssertionError("Failed to get to field of messsage", e);
}
}