Foren

Message board subscription email not working

thumbnail
Rahul Pande, geändert vor 10 Jahren.

Message board subscription email not working

Expert Beiträge: 310 Beitrittsdatum: 07.07.10 Neueste Beiträge
Hi All,

Liferay version : 6.0.6 CE

I have configured the smtp details from control panel to enable email from my machine. In message board all subscribed users of a category receives email notifications whenever anyone posts a new thread. It is working fine on my local machine, but it is not working on our Live or Test site though it is working for other emails (e.g user creation, password reset etc) emoticon. I am getting following error

04:45:25,818 ERROR [MailEngine:489] 554 Transaction failed: Empty address

04:45:25,818 ERROR [MailEngine:154] com.sun.mail.smtp.SMTPSendFailedException: 554 Transaction failed: Empty address

        at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
        at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1215)
        at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:586)
        at com.liferay.util.mail.MailEngine._send(MailEngine.java:462)
        at com.liferay.util.mail.MailEngine.send(MailEngine.java:366)
        at com.liferay.util.mail.MailEngine.send(MailEngine.java:110)
        at com.liferay.mail.messaging.MailMessageListener.doMailMessage(MailMessageListener.java:101)
        at com.liferay.mail.messaging.MailMessageListener.doReceive(MailMessageListener.java:115)
        at com.liferay.mail.messaging.MailMessageListener.receive(MailMessageListener.java:43)
        at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(InvokerMessageListener.java:63)
        at com.liferay.portal.kernel.messaging.ParallelDestination$1.run(ParallelDestination.java:61)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:722)


We are using Amazon SES for sending emails.

Any information will be helpful. emoticon

Thanks
Rahul
thumbnail
King N.B., geändert vor 10 Jahren.

RE: Message board subscription email not working

New Member Beiträge: 13 Beitrittsdatum: 28.08.13 Neueste Beiträge
Hello, Rahul

I am also facing same problem like you.

Version are both 6.1 CE GA3, 6.1 EE GA3.
Mail Service is using also Amazon SES.

While other Liferay mail functions are working well, message boards notification returns error with the same error log above.
# When I uses other mail server(not Amazon SES), message boards email notification works well.

I asked to Amazon SES Customer Support and got below answer.
>
> There are 2 possibilities
> *1. "TO" address header is missing
> *2. Liferay may use [essage/delivery-status] Content-Type that is not supported by Amazon SES
>
Rahul, currently how does you solve above issue?
Or could anybody please comment on this issues?

If in case of *1 or *2, are there any way to solve or overwrite Liferay current coding?
thumbnail
King N.B., geändert vor 10 Jahren.

RE: Message board subscription email not working

New Member Beiträge: 13 Beitrittsdatum: 28.08.13 Neueste Beiträge
Does anybody have update on this issue?
When I upgraded 6.1 GA3, then announcements portlet can deliver email by Site role(in GA2, can not deliver email by Site role, it seems bug)
I don't know if my comment is related to this post, but if there are anyone who has used AWS SES service, could you please let me know.
thumbnail
Thiago Leão Moreira, geändert vor 10 Jahren.

RE: Message board subscription email not working

Liferay Legend Beiträge: 1449 Beitrittsdatum: 10.10.07 Neueste Beiträge
Hi there,

I'm facing the same problem with Message Board and AWS SES, any updates on this issue? Following are the headers printed using the logging system:
MIME-Version: 1.0
Content-Type: text/html;charset="UTF-8"
Content-Transfer-Encoding: 7bit
thumbnail
Rahul Pande, geändert vor 10 Jahren.

RE: Message board subscription email not working

Expert Beiträge: 310 Beitrittsdatum: 07.07.10 Neueste Beiträge
Hi Thiago,

I don't know whether this is right way to fix this issue but following customization worked for me.

I have overridden com.liferay.mail.messaging.MailMessageListener class for this change. Default code sets bulk addresses to the message and then send the mail using MainEngine.send(mailMessage).


mailMessage.setBulkAddresses(bulkAddresses);

		if (((to != null) && (to.length > 0)) ||
			((cc != null) && (cc.length > 0)) ||
			((bcc != null) && (bcc.length > 0)) ||
			((bulkAddresses != null) && (bulkAddresses.length > 0))) {

			MailEngine.send(mailMessage);
		}


Sending mails by setting bulk addresses caused the issue, so solution was to iterate over individual address and then send mails.

MailMessage individualMessage = null
for(int i = 0; i < bulkAddresses.length; i++) {
					
				        individualMessage = new MailMessage(from, bulkAddresses[i] ,mailMessage.getSubject(), updatedBody, true);

					MailEngine.send(individualMessage);
					
				}


Please reply if you have any other solution.

Thanks
Rahul Pande
thumbnail
King N.B., geändert vor 10 Jahren.

RE: Message board subscription email not working

New Member Beiträge: 13 Beitrittsdatum: 28.08.13 Neueste Beiträge
How did you override com.liferay.mail.messaging.MailMessageListener class?
I recognized MailMessageListener can't be overrode by hook.
Did you modify the source code of the jar file and deploy them?
thumbnail
Rahul Pande, geändert vor 10 Jahren.

RE: Message board subscription email not working

Expert Beiträge: 310 Beitrittsdatum: 07.07.10 Neueste Beiträge
Hi King,

I override com.liferay.mail.messaging.MailMessageListener class using ext plugin.

Thank you,
Rahul Pande
thumbnail
King N.B., geändert vor 10 Jahren.

RE: Message board subscription email not working

New Member Beiträge: 13 Beitrittsdatum: 28.08.13 Neueste Beiträge
Hello Rahul
That's very helpful for me.

I also tried ext-plugin.

Could you please confirm whether my understanding is right.

I think your additional code represents to iterate one by one not by using bulkAddresses

>MailMessage individualMessage = null
>for(int i = 0; i < bulkAddresses.length; i++) {
>
> individualMessage = new MailMessage(from, bulkAddresses ,mailMessage.getSubject(), updatedBody, true);
>
> MailEngine.send(individualMessage);
>
> }


How where do you insert this code to MailMessageListener?

Because as below code,

>mailMessage.setBulkAddresses(bulkAddresses);
>
> if (((to != null) && (to.length > 0)) ||
> ((cc != null) && (cc.length > 0)) ||
> ((bcc != null) && (bcc.length > 0)) ||
> ((bulkAddresses != null) && (bulkAddresses.length > 0))) {
>
> MailEngine.send(mailMessage);
> }

mailMessage objects contains all to, cc, bcc, bulkAddresses.
Do you separate bulkAddresses part and pass another MailEngine.send?

If possible, could you please let me know over view codes.

Thanks in advance and very appreciated for your precious advices.

best regards,
thumbnail
Rahul Pande, geändert vor 10 Jahren.

RE: Message board subscription email not working

Expert Beiträge: 310 Beitrittsdatum: 07.07.10 Neueste Beiträge
King N.B.:
I think your additional code represents to iterate one by one not by using bulkAddresses


Yes, I'm iterating over the bulk addresses.

King N.B.:
How where do you insert this code to MailMessageListener?

Once you get the array of addresses, Null and length check the to, cc, bcc and bulAddress object. Create the body of the message and then iterate over the bulk addresses and send the mails using MailEngine
InternetAddress[] bulkAddresses = filterInternetAddresses(
			mailMessage.getBulkAddresses());

		if (((to != null) &amp;&amp; (to.length &gt; 0)) ||
			((cc != null) &amp;&amp; (cc.length &gt; 0)) ||
			((bcc != null) &amp;&amp; (bcc.length &gt; 0)) ||
			((bulkAddresses != null) &amp;&amp; (bulkAddresses.length &gt; 0))) {

			String updatedBody = HtmlUtil.unescape(mailMessage.getBody());
			
			// Iterating over bulk addresses and sending mail using MailServiceUtil class, because default
			// mail sending method is not working for Amazon SES
			if(bulkAddresses != null &amp;&amp; (bulkAddresses != null) &amp;&amp; (bulkAddresses.length &gt; 0)) {
				for(int i = 0; i &lt; bulkAddresses.length; i++) {
					
					MailMessage individualMessage = new MailMessage(from, bulkAddresses[i] ,mailMessage.getSubject(), updatedBody, true);

					MailEngine.send(individualMessage);
					
				}
			}else {
				MailEngine.send(mailMessage);
			}
		}


HTH
Rahul Pande
thumbnail
King N.B., geändert vor 10 Jahren.

RE: Message board subscription email not working

New Member Beiträge: 13 Beitrittsdatum: 28.08.13 Neueste Beiträge
Thanks! With your information, I deeply check the ralated code.
At first, I turned log level of com.liferay.util.mail to debug, and obtained below outputs.

[liferay/mail-2][MailEngine:188] To: []
--<omitted>--
[liferay/mail-2][MailEngine:195] Reply to: [ <>]

It is supporsed that To and Reply To, not set null, but empty mail address and it may cause empty address error.
I edited MailEngine via plugin-ext to set null to To, Reply To, then SES can send mails.

Best regards,
thumbnail
Rahul Pande, geändert vor 10 Jahren.

RE: Message board subscription email not working

Expert Beiträge: 310 Beitrittsdatum: 07.07.10 Neueste Beiträge
Hi King,

Glad to know that it worked. emoticon
Can you please explain your solution or post the code if possible ?


Thanks
Rahul Pande
thumbnail
King N.B., geändert vor 10 Jahren.

RE: Message board subscription email not working (Antwort)

New Member Beiträge: 13 Beitrittsdatum: 28.08.13 Neueste Beiträge
Yes, Sure with pleasure.
What I did is to focus on com.liferay.util.mail.MailEngine where centricly execute mail delivery.
Method is send. When To or Reply-To is empty(Regard it when there is no @ char), set null.
My Quick and rough code is below. see the place "!See Here!" section. #Note that code is not tested at all

	public static void send(
			InternetAddress from, InternetAddress[] to, InternetAddress[] cc,
			InternetAddress[] bcc, InternetAddress[] bulkAddresses,
			String subject, String body, boolean htmlFormat,
			InternetAddress[] replyTo, String messageId, String inReplyTo,
			List<fileattachment> fileAttachments, SMTPAccount smtpAccount)
		throws MailEngineException {

		StopWatch stopWatch = null;

		if (_log.isDebugEnabled()) {
			stopWatch = new StopWatch();

			stopWatch.start();

			_log.debug("From: " + from);
			_log.debug("To: " + Arrays.toString(to));
			_log.debug("CC: " + Arrays.toString(cc));
			_log.debug("BCC: " + Arrays.toString(bcc));
			_log.debug("List Addresses: " + Arrays.toString(bulkAddresses));
			_log.debug("Subject: " + subject);
			_log.debug("Body: " + body);
			_log.debug("HTML Format: " + htmlFormat);
			_log.debug("Reply to: " + Arrays.toString(replyTo));
			_log.debug("Message ID: " + messageId);
			_log.debug("In Reply To: " + inReplyTo);
			if ((fileAttachments != null) &amp;&amp; _log.isDebugEnabled()) {
				for (int i = 0; i &lt; fileAttachments.size(); i++) {
					FileAttachment fileAttachment = fileAttachments.get(i);

					File file = fileAttachment.getFile();

					if (file == null) {
						continue;
					}

					_log.debug(
						"Attachment " + i + " file " + file.getAbsolutePath() +
							" and file name " + fileAttachment.getFileName());
				}
			}
		}

		try {
			Session session = null;

			if (smtpAccount == null) {
				session = getSession();
			}
			else {
				session = getSession(smtpAccount);
			}

			Message message = new LiferayMimeMessage(session);

			message.addHeader(
				"X-Auto-Response-Suppress", "AutoReply, DR, NDR, NRN, OOF, RN");

			//add-hoc code. Not Tested. Please use carefully.!See Here!
			if(Arrays.toString(to).indexOf("@") == -1) {
				to = null;
			}
			if(Arrays.toString(replyTo).indexOf("@") == -1) {
				replyTo = null;
			}
			//////////////////////////////////////////////////
			message.setFrom(from);
			message.setRecipients(Message.RecipientType.TO, to);

			if (cc != null) {
				message.setRecipients(Message.RecipientType.CC, cc);
			}

			if (bcc != null) {
				message.setRecipients(Message.RecipientType.BCC, bcc);
			}

			subject = GetterUtil.getString(subject);

			message.setSubject(subject);

			if ((fileAttachments != null) &amp;&amp; (fileAttachments.size() &gt; 0)) {
				MimeMultipart rootMultipart = new MimeMultipart(
					_MULTIPART_TYPE_MIXED);

				MimeMultipart messageMultipart = new MimeMultipart(
					_MULTIPART_TYPE_ALTERNATIVE);

				MimeBodyPart messageBodyPart = new MimeBodyPart();

				messageBodyPart.setContent(messageMultipart);

				rootMultipart.addBodyPart(messageBodyPart);

				if (htmlFormat) {
					MimeBodyPart bodyPart = new MimeBodyPart();

					bodyPart.setContent(body, _TEXT_HTML);

					messageMultipart.addBodyPart(bodyPart);
				}
				else {
					MimeBodyPart bodyPart = new MimeBodyPart();

					bodyPart.setText(body);

					messageMultipart.addBodyPart(bodyPart);
				}

				for (int i = 0; i &lt; fileAttachments.size(); i++) {
					FileAttachment fileAttachment = fileAttachments.get(i);

					File file = fileAttachment.getFile();

					if (file == null) {
						continue;
					}

					MimeBodyPart mimeBodyPart = new MimeBodyPart();

					DataSource dataSource = new FileDataSource(file);

					mimeBodyPart.setDataHandler(new DataHandler(dataSource));
					mimeBodyPart.setDisposition(Part.ATTACHMENT);

					if (fileAttachment.getFileName() != null) {
						mimeBodyPart.setFileName(fileAttachment.getFileName());
					}
					else {
						mimeBodyPart.setFileName(file.getName());
					}

					rootMultipart.addBodyPart(mimeBodyPart);
				}

				message.setContent(rootMultipart);

				message.saveChanges();
			}
			else {
				if (htmlFormat) {
					message.setContent(body, _TEXT_HTML);
				}
				else {
					message.setContent(body, _TEXT_PLAIN);
				}
			}

			message.setSentDate(new Date());

			if (replyTo != null) {
				message.setReplyTo(replyTo);
			}

			if (messageId != null) {
				message.setHeader("Message-ID", messageId);
			}

			if (inReplyTo != null) {
				message.setHeader("In-Reply-To", inReplyTo);
				message.setHeader("References", inReplyTo);
			}

			int batchSize = GetterUtil.getInteger(
				PropsUtil.get(PropsKeys.MAIL_BATCH_SIZE), _BATCH_SIZE);

			_send(session, message, bulkAddresses, batchSize);
		}
		catch (SendFailedException sfe) {
			_log.error(sfe);
		}
		catch (Exception e) {
			throw new MailEngineException(e);
		}

		if (_log.isDebugEnabled()) {
			_log.debug("Sending mail takes " + stopWatch.getTime() + " ms");
		}
	}</fileattachment>
thumbnail
Thiago Leão Moreira, geändert vor 10 Jahren.

RE: Message board subscription email not working

Liferay Legend Beiträge: 1449 Beitrittsdatum: 10.10.07 Neueste Beiträge
Hi there,

I fixed the problem adding the following properties to the Mail section in the Control Painel.
mail.smtp.auth=true
mail.smtp.starttls.enable=true
mail.smtp.starttls.required=true


I also had to turned off the SSL connection, I had to use the 465 port. The problem was happening on 6.2 too.
thumbnail
Eric Min, geändert vor 10 Jahren.

RE: Message board subscription email not working

Junior Member Beiträge: 31 Beitrittsdatum: 05.10.09 Neueste Beiträge
Hi Thiago,

I tired your solution but I still faced the same problems, any ideas?

Thanks.
thumbnail
Thiago Leão Moreira, geändert vor 10 Jahren.

RE: Message board subscription email not working

Liferay Legend Beiträge: 1449 Beitrittsdatum: 10.10.07 Neueste Beiträge
Hey Eric,

I thought that I solved the problem but once I restarted the server the process of send email stopped to work. I'm back to the step 0 again.
thumbnail
Eric Min, geändert vor 10 Jahren.

RE: Message board subscription email not working

Junior Member Beiträge: 31 Beitrittsdatum: 05.10.09 Neueste Beiträge
LPS-44849 and LPS-45488 will fix this issue.
Umesh Asodekar, geändert vor 8 Jahren.

RE: Message board subscription email not working

New Member Beitrag: 1 Beitrittsdatum: 31.12.15 Neueste Beiträge
hello,

first of all, thank you.
@Thiago Leão Moreira for the idea and solution.

My need is here i want to throw the exception like UnknownHostException and SendFailedException to my self written class instead of just printing logs in MailEngine class as they have done.
i want to catch those exception to my self written class. so i want to override cMailEngine class to send those exception to my class

So i'm in need of overriding MailEngine class. Can you please help to explain exact steps to override this class.