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


Java SimpleMailMessage.setCc方法代碼示例

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


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

示例1: sendMessageCc

import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
public boolean sendMessageCc(String mailFrom, String mailTo,String Cc, String subject, String mailMessage) {

SimpleMailMessage mail = new SimpleMailMessage();  

if(this.isEnabled) {
  	try {
   		mail.setFrom(mailFrom);
	    mail.setTo(mailTo);
	    mail.setSubject(subject);
	    mail.setText(mailMessage);
	    mail.setCc(Cc);
        mailSender.send(mail);
        
        log.debug("Email sent : " + mail.toString());
        //logService.logMail(mailTo, mailMessage, LogService.MAIL_SENT);
   	} catch(Exception e) {   		
        log.error("Email failed : " + mail.toString(), e);
        //logService.logMail(mailTo, mailMessage, LogService.MAIL_FAILED);
        return false;
   	}
} else {
	log.warn("sendMessage called but email is not enabled ...");
	log.info("\tmethod call was :  sendMessage(" + mailFrom + ", " + mailTo +", "+Cc+ ", " + subject + ", " + mailMessage + ")");
}
return true;
  }
 
開發者ID:EsupPortail,項目名稱:esup-sgc,代碼行數:27,代碼來源:EmailService.java

示例2: send

import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
@Override
public void send(MailMessage message) throws MailSenderException {
    SimpleMailMessage smm = new SimpleMailMessage();
    MailBody body = message.getBody();
    smm.setText(MailUtils.toPlainText(body));
    MailHead head = message.getHead();
    smm.setFrom(head.getFrom());
    smm.setReplyTo(head.getReplyTo());
    smm.setSubject(head.getSubject());
    smm.setTo(asArray(head.getTo()));
    smm.setCc(asArray(head.getCc()));
    smm.setBcc(asArray(head.getBcc()));
    smm.setSentDate(head.getSentDate());
    LOG.info("message to send {}", smm);
    mailSender.send(smm);
}
 
開發者ID:codeabovelab,項目名稱:haven-platform,代碼行數:17,代碼來源:SpringMailSenderBackend.java

示例3: sendEmail

import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
/**
    * Construct and a send simple email message from a Mail Message.
    * 
    * @param message
    *            the Mail Message
 * @throws MessagingException 
    */
@Override
      @SuppressWarnings("unchecked")
public void sendEmail(MailMessage message) throws MessagingException {
       
       // Construct a simple mail message from the Mail Message
       SimpleMailMessage smm = new SimpleMailMessage();
       smm.setTo( (String[])message.getToAddresses().toArray(new String[message.getToAddresses().size()]) );
       smm.setBcc( (String[])message.getBccAddresses().toArray(new String[message.getBccAddresses().size()]) );
       smm.setCc( (String[])message.getCcAddresses().toArray(new String[message.getCcAddresses().size()]) );
       smm.setSubject(message.getSubject());
       smm.setText(message.getMessage());
       smm.setFrom(message.getFromAddress());

       try {
       	if ( LOG.isDebugEnabled() ) {
       		LOG.debug( "sendEmail() - Sending message: " + smm.toString() );
       	}
           mailSender.send(smm);
       }
       catch (Exception e) {
       	LOG.error("sendEmail() - Error sending email.", e);
		throw new RuntimeException(e);
       }
   }
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:32,代碼來源:MailerImpl.java

示例4: javaMailSenderWithSimpleMessage

import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
@Test
public void javaMailSenderWithSimpleMessage() throws MessagingException, IOException {
	MockJavaMailSender sender = new MockJavaMailSender();
	sender.setHost("host");
	sender.setPort(30);
	sender.setUsername("username");
	sender.setPassword("password");

	SimpleMailMessage simpleMessage = new SimpleMailMessage();
	simpleMessage.setFrom("[email protected]");
	simpleMessage.setReplyTo("[email protected]");
	simpleMessage.setTo("[email protected]");
	simpleMessage.setCc(new String[] {"[email protected]", "[email protected]"});
	simpleMessage.setBcc(new String[] {"[email protected]", "[email protected]"});
	Date sentDate = new GregorianCalendar(2004, 1, 1).getTime();
	simpleMessage.setSentDate(sentDate);
	simpleMessage.setSubject("my subject");
	simpleMessage.setText("my text");
	sender.send(simpleMessage);

	assertEquals("host", sender.transport.getConnectedHost());
	assertEquals(30, sender.transport.getConnectedPort());
	assertEquals("username", sender.transport.getConnectedUsername());
	assertEquals("password", sender.transport.getConnectedPassword());
	assertTrue(sender.transport.isCloseCalled());

	assertEquals(1, sender.transport.getSentMessages().size());
	MimeMessage sentMessage = sender.transport.getSentMessage(0);
	List<Address> froms = Arrays.asList(sentMessage.getFrom());
	assertEquals(1, froms.size());
	assertEquals("[email protected]", ((InternetAddress) froms.get(0)).getAddress());
	List<Address> replyTos = Arrays.asList(sentMessage.getReplyTo());
	assertEquals("[email protected]", ((InternetAddress) replyTos.get(0)).getAddress());
	List<Address> tos = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.TO));
	assertEquals(1, tos.size());
	assertEquals("[email protected]", ((InternetAddress) tos.get(0)).getAddress());
	List<Address> ccs = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.CC));
	assertEquals(2, ccs.size());
	assertEquals("[email protected]", ((InternetAddress) ccs.get(0)).getAddress());
	assertEquals("sh[email protected]", ((InternetAddress) ccs.get(1)).getAddress());
	List<Address> bccs = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.BCC));
	assertEquals(2, bccs.size());
	assertEquals("[email protected]", ((InternetAddress) bccs.get(0)).getAddress());
	assertEquals("[email protected]", ((InternetAddress) bccs.get(1)).getAddress());
	assertEquals(sentDate.getTime(), sentMessage.getSentDate().getTime());
	assertEquals("my subject", sentMessage.getSubject());
	assertEquals("my text", sentMessage.getContent());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:49,代碼來源:JavaMailSenderTests.java

示例5: sendSimpleMailWithoutAttachment

import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
private void sendSimpleMailWithoutAttachment(String fromAddress, List<String> toAddress, List<String> ccAddress, String subject, final String mailContent) {
    SimpleMailMessage email = new SimpleMailMessage();
    email.setFrom(fromAddress);
    email.setTo(toAddress.toArray(new String[toAddress.size()]));
    if (ccAddress != null && ccAddress.size() > 0) {
        email.setCc(ccAddress.toArray(new String[ccAddress.size()]));
    }
    email.setSubject(subject);
    email.setText(mailContent);
    mailSender.send(email);
    log.debug("Text Mail successfully sent !! \nFrom Addres: " + fromAddress + " To Address: " + toAddress + " CC Address: " + ccAddress + "\n Subject: " + subject);
}
 
開發者ID:Mahidharmullapudi,項目名稱:timesheet-upload,代碼行數:13,代碼來源:EmailServiceImpl.java

示例6: sendPlainText

import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
public static void sendPlainText(String to, String cc, String from, String subject, String text) {
    logger.info("sendPlainText");
    
    if (to.contains(",")) {
        to = to.replace(",", "");
    }
    if (to.contains(":")) {
        to = to.replace(":", "");
    }
            
    SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
    simpleMailMessage.setTo(to);
    if (StringUtils.isNotBlank(cc)) {
        simpleMailMessage.setCc(cc);
    }
    simpleMailMessage.setBcc(ADMIN_EMAIL);
    simpleMailMessage.setFrom(from);
    simpleMailMessage.setSubject(subject);
    simpleMailMessage.setText(text);

    JavaMailSenderImpl javaMailSenderImpl = new JavaMailSenderImpl();
    String smtpHost = ConfigHelper.getProperty("smtp.host");
    javaMailSenderImpl.setHost(smtpHost);

    logger.info("Sending e-mail to " + simpleMailMessage.getTo()[0] + " with subject \"" + simpleMailMessage.getSubject() + "\"...");
    logger.info("Text: " + simpleMailMessage.getText());
    if (EnvironmentContextLoaderListener.env != Environment.DEV) {
        javaMailSenderImpl.send(simpleMailMessage);
    }
}
 
開發者ID:elimu-ai,項目名稱:webapp,代碼行數:31,代碼來源:Mailer.java

示例7: sendTextMail

import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
@Override
public void sendTextMail(final MailMetaData mailMetaData, final String text) {
	if (suppressMail) {
		return;
	}
	final SimpleMailMessage mailMessage = new SimpleMailMessage();
	mailMessage.setFrom(new StringBuilder().append(mailMetaData.getFromName()).append(" <").append(mailMetaData.getFromAddress())
			.append(">").toString());
	mailMessage.setSubject(mailMetaData.getSubject());
	mailMessage.setReplyTo(mailMetaData.getReplyTo());
	if (mailMetaData.getCcAddresses() != null && mailMetaData.getCcAddresses().size() > 0) {
		mailMessage.setCc((String[]) mailMetaData.getCcAddresses().toArray(new String[mailMetaData.getCcAddresses().size()]));
	}
	if (mailMetaData.getBccAddresses() != null && mailMetaData.getBccAddresses().size() > 0) {
		mailMessage.setBcc((String[]) mailMetaData.getBccAddresses().toArray(new String[mailMetaData.getBccAddresses().size()]));
	}
	if (mailMetaData.getToAddresses() != null && mailMetaData.getToAddresses().size() > 0) {
		mailMessage.setTo((String[]) mailMetaData.getToAddresses().toArray(new String[mailMetaData.getToAddresses().size()]));
	}
	mailMessage.setText(text);
	try {
		mailSender.send(mailMessage);
	} catch (MailException e) {
		throw new SendMailException(new StringBuilder().append("Error sending mail: ").append(mailMetaData.toString()).toString(),
				e);
	}
}
 
開發者ID:kuzavas,項目名稱:ephesoft,代碼行數:28,代碼來源:MailServiceImpl.java

示例8: sendTextMail

import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
/**
 * API to send mail using javaMailSender.
 * 
 * @param mailMetaData
 * @param text
 * @throws WizardMailException
 */
private void sendTextMail(final MailMetaData mailMetaData, final String text) throws WizardMailException {
	LOGGER.info("Entering method sendTextMail....");
	final SimpleMailMessage mailMessage = new SimpleMailMessage();
	mailMessage.setFrom(new StringBuilder().append(mailMetaData.getFromName()).append(MailConstants.SPACE).append(
			MailConstants.LESS_SYMBOL).append(mailMetaData.getFromAddress()).append(MailConstants.GREATER_SYMBOL).toString());
	mailMessage.setSubject(mailMetaData.getSubject());
	mailMessage.setReplyTo(mailMetaData.getReplyTo());
	if (mailMetaData.getCcAddresses() != null && mailMetaData.getCcAddresses().size() > 0) {
		mailMessage.setCc((String[]) mailMetaData.getCcAddresses().toArray(new String[mailMetaData.getCcAddresses().size()]));
	}
	if (mailMetaData.getBccAddresses() != null && mailMetaData.getBccAddresses().size() > 0) {
		mailMessage.setBcc((String[]) mailMetaData.getBccAddresses().toArray(new String[mailMetaData.getBccAddresses().size()]));
	}
	if (mailMetaData.getToAddresses() != null && mailMetaData.getToAddresses().size() > 0) {
		mailMessage.setTo((String[]) mailMetaData.getToAddresses().toArray(new String[mailMetaData.getToAddresses().size()]));
	}
	mailMessage.setText(text);
	try {
		LOGGER.info("Sending mail using JavaMailSender....");
		wizardMailSender.send(mailMessage);
	} catch (MailException e) {
		LOGGER.error("Exception occured during sending Email.Email meta deta is " + mailMetaData.toString() + ".Excption is "
				+ e.getMessage(), e);
		throw new WizardMailException(new StringBuilder().append("Error sending mail: ").append(mailMetaData.toString())
				.toString(), e);
	}
	LOGGER.info("Mail sent successfully.Exiting method sendTextMail....");
}
 
開發者ID:kuzavas,項目名稱:ephesoft,代碼行數:36,代碼來源:WizardMailServiceImpl.java


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