1   package com.atlassian.mail.queue;
2   
3   import com.atlassian.mail.Email;
4   import com.atlassian.mail.MailException;
5   import com.atlassian.mail.MailFactory;
6   import com.atlassian.mail.server.SMTPMailServer;
7   import org.apache.log4j.Logger;
8   
9   public class SingleMailQueueItem extends AbstractMailQueueItem
10  {
11      private static final Logger LOG = Logger.getLogger(SingleMailQueueItem.class);
12  
13      private final Email email;
14  
15      public SingleMailQueueItem(Email email)
16      {
17          super(email.getSubject());
18          this.email = email;
19      }
20  
21      public void send() throws MailException
22      {
23          incrementSendCount();
24  
25          SMTPMailServer smtpMailServer = MailFactory.getServerManager().getDefaultSMTPMailServer();
26  
27          if (smtpMailServer == null)
28          {
29              LOG.debug("Not sending message as the default SMTP Mail Server is not defined.");
30              return;
31          }
32  
33          // Check if mailing is disabled && if SMTPMailServer has been set
34          if (!MailFactory.getSettings().isSendingDisabled())
35          {
36              // MAIL-77: Allow MailThreader to set a custom Message-ID if required
37              String customMessageId = null;
38              if (mailThreader != null)
39              {
40                  mailThreader.threadEmail(email);
41                  customMessageId = mailThreader.getCustomMessageId(email);
42              }
43              // Send the message
44              smtpMailServer.sendWithMessageId(email, customMessageId);
45              if (mailThreader != null) mailThreader.storeSentEmail(email);
46          }
47  		else
48  		{
49  			LOG.debug("Not sending message as sending is turned off.");
50          }
51      }
52  
53      public Email getEmail()
54      {
55          return email;
56      }
57  
58      public String toString()
59      {
60          return (email != null ? email.toString() : "null");
61      }
62  }