Send Email in JIRA servlet plugin

i have created a servlet plugin for jira, and want to send mail in this servlet. it works ok in my local server, when i deployed it to our integration server, it doesn't work, the integration server have configed the mail server and enabled. anyone can give me a suggestion? the code as below:


SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer();

if (mailServer == null)
{
       LOG.debug("Not sending message as the default SMTP Mail Server is not defined.");
return;
}

if (!MailFactory.getSettings().isSendingDisabled())
{
Email mail = new Email(to);
mail.setSubject(subject);

Multipart mainPart = new MimeMultipart();
MimeBodyPart messageBodyPart = new MimeBodyPart();//创建一个包含HTML内容的MimeBodyPart
//设置HTML内容
messageBodyPart.setContent(body,"text/html; charset=utf-8");
mainPart.addBodyPart(messageBodyPart);
mail.setMultipart(mainPart);

mailServer.send(mail);
}
else
{
LOG.debug("Not sending message as sending is turned off.");
}

3 answers

This widget could not be displayed.

Hey Simon,

What do you see in the logs?

Thanks

Bhushan

Hi Bhushan,

there no any errors in the log file, so i don't know how to solve this problem, after all it works ok in our local server, and i can get the email. in my plugin i will send a mail and then save some data into the database, when i run the plugin in the intergration server i cannot get the mail but the data has ben stored, and i check the log file there no error.

 

thanks

This widget could not be displayed.

Hi 

i have done same email work in my servlet class so please try this.

public void sendEmailToUser(){
System.out.println("Sending email to user....");
try{
String baseUrl = settingsManager.getGlobalSettings().getBaseUrl();
String confluencePageURL = pageManager.getPage(pageId).getUrlPath();
String PageLinkInJira = baseUrl + confluencePageURL;
String to = "anil@abc.com";
String subject = "Data Request Form Error";
String Pagebody = "Test body";
MailQueueItem testingMailQue=new ConfluenceMailQueueItem(to, subject, Pagebody, MIME_TYPE_HTML);
String to2="email2";
MailQueueItem mailque=new ConfluenceMailQueueItem(to2, subject, Pagebody, MIME_TYPE_HTML);
System.out.println("mail sending ........");
taskManager.addTask(MAIL, testingMailQue);
taskManager.addTask(MAIL, mailque);
System.out.println("mail sent .......");
}
catch (Exception e) {
System.out.println("General Exception " + e.getMessage());
e.printStackTrace();
}
}

Hope it will helpful for you

Anil Singh

Programmer Analyst

http://www.mirketa.com/

 

 

 

 

Anil,

how to inject taskManager to this class, because i am completely new comer, so i don't know how to add the mail to a queue, i have tried use SingleMailQueueItem to send mail, i get the same result, in my local server it works ok, but doesn't work on the intergration server, coed like below

public void sendEmail(String to, String subject, String body)
{

try {
Email mail = new Email(to);
mail.setSubject(subject);

Multipart mainPart = new MimeMultipart();
MimeBodyPart messageBodyPart = new MimeBodyPart();//创建一个包含HTML内容的MimeBodyPart
//设置HTML内容
messageBodyPart.setContent(body,"text/html; charset=utf-8");
mainPart.addBodyPart(messageBodyPart);
mail.setMultipart(mainPart);

MailQueueItem mailQueueItem = new SingleMailQueueItem(mail);

mailQueueItem.send();
} catch (MailException e) {

e.printStackTrace();
} catch (MessagingException e) {

e.printStackTrace();
}

}

This widget could not be displayed.

Please check your SMTP server and email settings

 

i think the SMTP server is ok, because it can send email to me when i assign a task to me in jira system, and i can get the email correctly.

this is the mail i get from my local server, and the same jar upload to intergration server i cannot get any emails, so strange...1496997576(1).png

this is the mail i get from intergration server when i assign a task to me, so i think the smtp server is ok.

1496997763(1).png

hi,

i found the error in another log file, the error like below:

Caused by: javax.mail.MessagingException: IOException while sending message;
nested exception is:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;
boundary="----=_Part_388_1975592549.1496992876233"
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1245)
at com.atlassian.mail.server.impl.SMTPMailServerImpl.sendMimeMessage(SMTPMailServerImpl.java:226)
at com.atlassian.mail.server.managers.EventAwareSMTPMailServer.sendMimeMessage(EventAwareSMTPMailServer.java:25)
at com.atlassian.mail.server.impl.SMTPMailServerImpl.sendWithMessageId(SMTPMailServerImpl.java:176)
... 208 more

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

181 views 2 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you