Hi everybody,
i'm using groovyrunner for sending an email without using the default JIRA smtp server.
I'm using the script as a post function in close workflow transition.
I have performed some tests and the script works fine when the host of my smtp mail server is Google Apps.
But when i use a custom smtp host my script doesn't work.
The script i use is the following
import javax.mail.internet.*;
import javax.mail.*
import javax.activation.*
import javax.mail.Multipart;
import javax.mail.internet.MimeMultipart;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.comments.CommentManager;
import com.atlassian.jira.issue.attachment.Attachment;
import com.atlassian.jira.issue.history.ChangeItemBean;
import com.atlassian.jira.util.AttachmentUtils;
import groovy.text.GStringTemplateEngine;
//Get Comment Manager
CommentManager commentManager = componentManager.getCommentManager();
//Get custom field manager
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
//Get custom field email by id
CustomField customField_email = customFieldManager.getCustomFieldObject( 10205 );
//get value of customField_email
to = issue.getCustomFieldValue( customField_email )
//Email Headers
sender="test@gmail.com"
sendername="Test Test"
//Email acccount credentials
username="test@gmail.com"
password="test"
//Gmail Default port
port = 465
//Email Body
content = """\
<html>
<body>
<div>
test
</div>
</body>
</html>
"""
//Creat first part of email, Email Body
Multipart mp = new MimeMultipart("mixed");
MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent(content.toString(), "text/html");
mp.addBodyPart(htmlPart);
//Email Properties
props = new Properties()
props.put("mail.smtp.port", port);
props.put("mail.smtp.socketFactory.fallback", "false");
props.put("mail.smtp.quitwait", "false");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
//New session
Session session = Session.getDefaultInstance(props);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(sender,sendername));
message.setSubject("${issue.getKey()}");
message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setContent(mp)
try{
Transport transport = session.getTransport("smtp");
transport.connect( "smtp.gmail.com",port,username,password );
transport.sendMessage(message,message.getAllRecipients());
transport.close();
log.warn ("mail sent sucesfully to : "+ issue.getCustomFieldValue( customField_email).toString())
}catch (MessagingException mex) {
mex.printStackTrace();
}
When i choose the transition that scipt should executed i get no errors in logs but the following warning on screen

After that issue is like in no status. I have to reindex if i want to perform any workflow action on it.
Email is not sent.
Any idea what may cause the problem?
Cheers,
Kostas