/*
 * Copyright 2010-2011 Ning, Inc.
 *
 * Ning licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.ning.billing.util.email;

import java.util.List;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.inject.Inject;

public class DefaultEmailSender implements EmailSender { 
    private final Logger log = LoggerFactory.getLogger(EmailSender.class);
    private final EmailConfig config;

    @Inject
    public DefaultEmailSender(EmailConfig emailConfig) {
        this.config = emailConfig;
    }

    @Override
    public void sendSecureEmail(List<String> to, List<String> cc, String subject, String htmlBody) throws EmailApiException {
        HtmlEmail email;
        try {
            email = new HtmlEmail();

            email.setSmtpPort(config.getSmtpPort());
            email.setAuthentication(config.getSmtpUserName(), config.getSmtpPassword());
            email.setHostName(config.getSmtpServerName());
            email.setFrom(config.getSmtpUserName());
            email.setSubject(subject);
            email.setHtmlMsg(htmlBody);

            if (to != null) {
                for (String recipient : to) {
                    email.addTo(recipient);
                }
            }

            if (cc != null) {
                for (String recipient : cc) {
                    email.addCc(recipient);
                }
            }

            email.setSSL(true);
            email.send();
        } catch (EmailException ee)  {
            log.warn("Failed to send e-mail", ee);
        }
    }
}

@@ -916,17 +916,16 @@
 Sender %7B
- 
 %0A    pri
@@ -1073,16 +1073,22 @@
 lSender(
+final 
 EmailCon
@@ -1194,16 +1194,22 @@
 reEmail(
+final 
 List%3CStr
@@ -1216,16 +1216,22 @@
 ing%3E to,
+ final
  List%3CSt
@@ -1239,16 +1239,22 @@
 ing%3E cc,
+ final
  String 
@@ -1261,16 +1261,22 @@
 subject,
+ final
  String 
@@ -1320,16 +1320,22 @@
         
+final 
 HtmlEmai
@@ -1772,32 +1772,38 @@
            for (
+final 
 String recipient
@@ -1939,16 +1939,22 @@
    for (
+final 
 String r
@@ -2140,17 +2140,16 @@
 tion ee)
- 
  %7B%0A     

reformat DefaultEmailSender