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.");
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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();
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Simon,
What do you see in the logs?
Thanks
Bhushan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.