001
014
015 package com.liferay.portlet.messageboards.util;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.mail.Account;
020 import com.liferay.portal.kernel.mail.SMTPAccount;
021 import com.liferay.portal.kernel.util.GetterUtil;
022 import com.liferay.portal.kernel.util.StringPool;
023 import com.liferay.portal.util.SubscriptionSender;
024 import com.liferay.portlet.messageboards.NoSuchMailingListException;
025 import com.liferay.portlet.messageboards.model.MBMailingList;
026 import com.liferay.portlet.messageboards.service.MBMailingListLocalServiceUtil;
027
028
032 public class MBSubscriptionSender extends SubscriptionSender {
033
034 public void addMailingListSubscriber(long groupId, long categoryId)
035 throws PortalException, SystemException {
036
037 if (_calledAddMailingListSubscriber) {
038 throw new IllegalArgumentException();
039 }
040
041 _calledAddMailingListSubscriber = true;
042
043 MBMailingList mailingList = null;
044
045 try {
046 mailingList = MBMailingListLocalServiceUtil.getCategoryMailingList(
047 groupId, categoryId);
048 }
049 catch (NoSuchMailingListException nsmle) {
050 return;
051 }
052
053 if (!mailingList.isActive()) {
054 return;
055 }
056
057 setFrom(mailingList.getOutEmailAddress(), null);
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 }