Announcement Announcement Module
Collapse
No announcement yet.
BCC and CC not working with JavaMailSender Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • BCC and CC not working with JavaMailSender

    I try to send an email to a couple of addresses on BCC with the below code.
    What happens is that the only address receiving an email is the one I set with setTo.
    Also in that email the receipiant I set with setCc appears but never gets an email, also the ones set with setBcc don't.
    The variables a correctly populated (especially mail.getBcc()), as far as i can tell.
    Attached you will find my logfile (had to zip it) and further below the logging-config.
    I would be very thankful for any hints or links. I couldn't find anything in the forums and I'm quite new to Spring, I'm afraid.
    There are NO exceptions occuring and also I can find no helpful information in the logging.
    Many greetings
    Marc

    Code:
                MimeMessage message = sender.createMimeMessage();
                MimeMessageHelper helper = new MimeMessageHelper(message, MimeMessageHelper.MULTIPART_MODE_RELATED, mimeMessageEncoding);
    
                helper.setTo(mail.getTo());
                helper.setCc(mail.getCc());
                helper.setBcc(mail.getBcc());
                helper.setFrom(mail.getFrom());
                helper.setSubject(mail.getSubject());
                helper.setText(mail.getText(), true);
    
                if (!mail.getInlineResources().isEmpty()) {
                    for(InlineResource ir : mail.getInlineResources()) {
                    		if (ir.getCid() != null && ir.getContent() != null && ir.getContentType() != null) {
                    			helper.addInline(ir.getCid(), new ByteArrayResource(ir.getContent()), ir.getContentType());
                    		} else {
                    			logger.error("Not enough data for inline resource.");
                    		}
                    }
                }
    
                if (!mail.getAttachments().isEmpty()) {
                    for(Attachment a : mail.getAttachments()) {
                    		if (a.getFilename() != null && a.getContent() != null && a.getContentType() != null) {
                    			helper.addAttachment(a.getFilename(), new ByteArrayResource(a.getContent()), a.getContentType());
                    		} else if (a.getFilename() != null && a.getContent() != null) {
                    			helper.addAttachment(a.getFilename(), new ByteArrayResource(a.getContent()));
                    		} else {
                    			logger.error("Not enough data for attachment."); 
                    		}
                    }
                }
    
                logger.debug("Message: " + message);
                sender.send(message);

    Because the information from the logging appears quite to be sparse (concerning the mailing part) here is also my log4j-config:


    HTML Code:
    log4j.logger.org.springframework=DEBUG, springopencms
    log4j.logger.org.springframework.web=DEBUG, springopencms
    log4j.logger.org.springframework.mail=DEBUG, springopencms
    log4j.logger.javax.mail=DEBUG, springopencms
    
    log4j.appender.springopencms=org.apache.log4j.RollingFileAppender
    
    log4j.appender.springopencms.File=/tmp/springlog.log
    
    log4j.appender.springopencms.MaxFileSize=5000KB
    
    log4j.appender.springopencms.MaxBackupIndex=5
    
    log4j.appender.springopencms.layout=org.apache.log4j.PatternLayout
    
    log4j.appender.springopencms.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

  • #2
    Can you add debug for the CC and BCC addresses and see if they are set properly?

    Code:
    logger.debug("CC -> " + mail.getCc());
    logger.debug("BCC -> " + mail.getBcc());
    I'm using CC addresses in my application(s) and they get the mail just fine.

    Comment


    • #3
      Logging

      Thank you for your interest.

      Logging looks like this:

      2008-11-17 13:38:37,717 [TP-Processor7] DEBUG de.mywebsite.business.MailService - CC -> [Ljava.lang.String;@59c7d395
      2008-11-17 13:38:40,840 [TP-Processor7] DEBUG de.mywebsite..business.MailService - BCC -> [Ljava.lang.String;@453130df

      debugging in eclipse get's me:
      mail.getCc(): (java.lang.String[]) [[email protected]]
      mail.getBcc(): (java.lang.String[]) [[email protected], [email protected]]

      Comment


      • #4
        solved

        After I finally was able to turn on logging, I found out that everything seems to be send correctly. It turned out, that my mailserver which has a catch-all simply doesn't deliver emails if the receipients from CC and BCC all belong to the same account (don't ask me why), it is the same when using other emailclients.

        In case anyone is interested, logging for javax.mail can be turned on by adding the following to the applicationCentext inside your mailing-bean:

        HTML Code:
        <property name="javaMailProperties">
        <props>
        	<prop key="mail.debug">true</prop>
        </props>
        </property>

        Comment

        Working...
        X