High Priority Email

0
Hey everyone, I was wondering if it is possible to give a "high priority" to an email that is send with the Email Module. I know it is possible you can add something like "X-Priority: 1 (Highest) X-MSMail-Priority: High" in the header of an email, but this doesn't work in Mendix. Anyone ever flagged an email with high priority when send by the module? Thanks!
asked
1 answers
2

This is inside Mendix mailModule and cannot be changed. But you can write your own mail java action, or copy the one below.

Inside that you must add, (better is to pass a parameter, but I leave that one to you).

Message.addHeader("X-Priority", "1");

Java action parameters:

String ToAddresses, 
String CCAddresses, 
String BCCAddresses, 
String FromAddress, 
String PlainBody, 
String HtmlBody, 
String SMTPHost, 
Long SMTPPort, 
String SMTPUserName, 
String SMTPPassword, 
String Subject, 
Boolean UseTLS

User code

    Properties props = new Properties();
    // create authenticator
    SMTPAuthenticator auth = new SMTPAuthenticator(SMTPUserName != null ? SMTPUserName : "", SMTPPassword != null ? SMTPPassword : "");
    // fill in mail properties
    props.setProperty("mail.transport.protocol", "smtp");
    props.put("mail.smtp.host", SMTPHost);
    //  necessary to use gmail 
    props.put("mail.smtp.starttls.enable", UseTLS ? "true" : "false"); 
    if (SMTPUserName != null && !"".equals(SMTPUserName.trim())) {
        props.put("mail.smtp.user", SMTPUserName); 
        props.put("mail.smtp.password", SMTPPassword);  
        props.put("mail.smtp.auth", "true");    
    }
    // portnumber
    props.put("mail.smtp.port", this.SMTPPort != null ? this.SMTPPort.intValue() : 25);  

    // create mailsession and message
    Session mailSession = Session.getDefaultInstance(props, auth);
    Message Message = new MimeMessage(mailSession);
    Message.addHeader("X-Priority", "1");
    try {
        // fill in from adress
        Message.setFrom(new InternetAddress(FromAddress));
        // subject
        Message.setSubject(Subject);
        // plain body text
        if (PlainBody != null && !"".equals(PlainBody.trim())) { 
            Message.setText(PlainBody);
        }
        // html body text
        if (HtmlBody != null && !"".equals(HtmlBody.trim())) { 
            Message.setContent(HtmlBody, "text/html");
        }

        // retrieve adresses TO
        if( this.ToAddresses != null && !"".equals(this.ToAddresses.trim()) ) {
            String[] addrArr = this.ToAddresses.split(",");
            for( String addr : addrArr ) 
                Message.addRecipient(RecipientType.TO, new InternetAddress(addr));
        }

        // retrieve adresses CC
        if( this.CCAddresses != null && !"".equals(this.CCAddresses.trim()) ) {
            String[] addrArr = this.CCAddresses.split(",");
            for( String addr : addrArr ) 
                Message.addRecipient(RecipientType.CC, new InternetAddress(addr));
        }

        // retrieve adresses BCC
        if( this.BCCAddresses != null && !"".equals(this.BCCAddresses.trim()) ) {
            String[] addrArr = this.CCAddresses.split(",");
            for( String addr : addrArr ) 
                Message.addRecipient(RecipientType.BCC, new InternetAddress(addr));
        }

        // actual send message
        Transport.send(Message);            
    } catch (MessagingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
answered