Failure sending emails from core

Hello Everyone,

I am trying to send and email from core, When i set the props, create the session and manage every with the code that i add, it all works well but then @wluyima directed me on using the message service as it already pre-built for it and will reduce redundant code but i get the error ERROR - MailMessageSender.send(72) |2018-08-15 15:27:53,224| failed to send message com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. j6-v6sm34538973wrs.91 - gsmtp,

when i just call messageService.send(message).

full stack trace is here https://pastebin.com/gVKynmJV

I wish to know how the default session is created and what are it default props values if i don’t explicitly create it as is the case with messageService.

@dkayiwa @wluyima

This is an issue with sending the email over a secure connection, are you sure you are configuring all the necessary properties properly? What do your email related GP values look like? Of course minus the username and password, can you share them?

Here is the global property configuration structure.

Then i have a simple message like this.

Message mail = new Message();

mail.setId(20);

	mail.setRecipients(user.getEmail());
	mail.setSender(Context.getAdministrationService().getGlobalProperty("mail.user"));
	mail.setContentType(Context.getAdministrationService().getGlobalProperty("mail.default_content_type"));
	mail.setSubject("Password Reset Request");
	mail.setContent(msg);
	mail.setSentDate(new Date());
	
	try {
		Context.getMessageService().sendMessage(mail);
	}
	catch (MessageException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

The error message actually is clear and gives a hint, when I glance at the code I see that the mail.smtp.starttls.enable isn’t getting set on the default mail session that comes with core, can you fix that and add it please?

@wyclif should i fix it to be set in the default mail session by default or I just set it for my work purpose. I want to suggest it should be set by default in the session say maybe to false.

It’s a bug in core that it’s not setting it, so you need to fix it.

Alternatively you can can create a core ticket to fix it and issue a PR for it, can you do that please? Thanks!

Do we know if this works? I tried this and it fails with some template error.