Email module - using TLS in mendix smtpConfiguration class

Hi guys, We are using email module for an earlier version (v336 of modeler) and using it with gmail smtp over SSL is all good, but with for example office365 smtp with TLS is not so straight forward. We would like to know how to use STARTTLS with the current smtpConfiguration class from mendix mail module. Enabling tls with just system.setProperty doesn't really work. Using Properties class works well, and we add Authenticator, etc, etc and we are able to send email through withTLS, but no attachments. How can we still use the original smtpConfiguartion and the neat method EmailModule.mail(config, this.HtmlBody, this.PlainBody, this.Subject, toList, ccList, bccList, this.getContext(), attachmentListIMx); with the TLS props enabled? LR. ps: this is related to email module - client was not authenticated question <<<<< ADDED >>>>> Seems there's no answer for this, I'm just surprised we cannot send emails using TLS with the current smtpConfiguration class. Why are we given the option to use SSL or TLS and then the core java mendix class doesn't support it?! I've removed the original java code and I am now using a more traditional approach. Have divided the text and attachments into two bodyparts for the email, and the first works. I'm able to send email using TLS, all good, but attachments don't work. I seem to have the handle on the object, filename, but not the path!! I recall that file path in mendix is not explicit, so how can I use this code to set the filepath and send the attachment in the email? # the smtp properties all set and textpart of the message all added# then, the second part, for the attachment... system.proxies.FileDocument FileDoc; for(int i = 0; i < this.AttachmentList.size();i++) { // Second part is attachment String filePath, filename = null; FileDoc = null; FileDoc = system.proxies.FileDocument.initialize(this.getContext(), this.AttachmentList.get(i).getMendixObject()); filename = FileDoc.getName(); info("Set the attachment for: " + filename); **filePath = "path of file to be attached";** DataSource source = new FileDataSource(filePath); pdfBodyPart.setDataHandler(new DataHandler(source)); pdfBodyPart.setFileName(filename); multipart.addBodyPart(pdfBodyPart); } // Send the complete message parts Message.setContent(multipart); info("All ready, transport the email!"); // actual send message Transport.send(Message); LR.
3 answers

You can set starttls in the properties. This must be done in the Java action.


To get the path use Core.getConfiguration().getTempPath();




Perhaps I'm approaching this the wrong way... How can I make us of the Mendix Email module class and "mail" method which allows the attachment lists directly with Mendix objects and make use of the TLS settings like the following?

Properties props = new Properties();
    props.put("", this.SMTPHost); //SMTP Host
    props.put("mail.smtp.port", ( this.SMTPPort != null ? this.SMTPPort.intValue() : 25)); //TLS Port
    props.put("mail.smtp.auth", "true"); //enable authentication
    props.put("mail.smtp.starttls.enable", "true"); //enable STARTTLS

            //create Authenticator object to pass in Session.getInstance argument
    Authenticator auth = new Authenticator() {
        //override the getPasswordAuthentication method
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication((SMTPUserName != null ? SMTPUserName : "" ), (SMTPPassword != null ? SMTPPassword : "" ));
    Session mailSession = Session.getInstance(props, auth);

If I use the usual smtpConfiguration, office365 smtp server doesn't authenticate the user, because the mendix mail method doesn't seem to handle properly tls, so how can I do this?

If I don't use the mail method, and use the properties as above and send email with MimeMessage and Transport.send(message), I can email correctly as long as I don't have attachments, because as soon as I add attachments, I cannot get the file path.

So, what would you guys suggest? Personally, I would rather use the mendix email module class, but I'm stuck either way. LR.