001
014
015 package com.liferay.portlet.messageboards.util;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.mail.Account;
019 import com.liferay.portal.kernel.mail.SMTPAccount;
020 import com.liferay.portal.kernel.util.GetterUtil;
021 import com.liferay.portal.kernel.util.StringPool;
022 import com.liferay.portal.util.SubscriptionSender;
023 import com.liferay.portlet.messageboards.NoSuchMailingListException;
024 import com.liferay.portlet.messageboards.model.MBMailingList;
025 import com.liferay.portlet.messageboards.service.MBMailingListLocalServiceUtil;
026
027
031 public class MBSubscriptionSender extends SubscriptionSender {
032
033 public void addMailingListSubscriber(long groupId, long categoryId)
034 throws PortalException {
035
036 if (_calledAddMailingListSubscriber) {
037 throw new IllegalArgumentException();
038 }
039
040 _calledAddMailingListSubscriber = true;
041
042 MBMailingList mailingList = null;
043
044 try {
045 mailingList = MBMailingListLocalServiceUtil.getCategoryMailingList(
046 groupId, categoryId);
047 }
048 catch (NoSuchMailingListException nsmle) {
049 return;
050 }
051
052 if (!mailingList.isActive()) {
053 return;
054 }
055
056 setFrom(mailingList.getOutEmailAddress(), null);
057 setReplyToAddress(mailingList.getEmailAddress());
058
059 if (mailingList.isOutCustom()) {
060 String protocol = Account.PROTOCOL_SMTP;
061
062 if (mailingList.isOutUseSSL()) {
063 protocol = Account.PROTOCOL_SMTPS;
064 }
065
066 SMTPAccount smtpAccount = (SMTPAccount)Account.getInstance(
067 protocol, mailingList.getOutServerPort());
068
069 smtpAccount.setHost(mailingList.getOutServerName());
070 smtpAccount.setUser(mailingList.getOutUserName());
071 smtpAccount.setPassword(mailingList.getOutPassword());
072
073 setSMTPAccount(smtpAccount);
074 }
075
076 setSubject(getMailingListSubject(subject, mailId));
077
078 addRuntimeSubscribers(
079 mailingList.getEmailAddress(), mailingList.getEmailAddress());
080 }
081
082 protected String getMailingListSubject(String subject, String mailId) {
083 subject = GetterUtil.getString(subject);
084 mailId = GetterUtil.getString(mailId);
085
086 return subject.concat(StringPool.SPACE).concat(mailId);
087 }
088
089 private boolean _calledAddMailingListSubscriber;
090
091 }