1 package org.telscenter.pas.ui.beans.issueReporter.actions;
2
3 import java.awt.event.ActionEvent;
4 import java.security.Security;
5 import java.util.Date;
6 import java.util.Properties;
7
8 import javax.mail.Message;
9 import javax.mail.PasswordAuthentication;
10 import javax.mail.Session;
11 import javax.mail.Transport;
12 import javax.mail.internet.InternetAddress;
13 import javax.mail.internet.MimeMessage;
14 import javax.swing.ImageIcon;
15
16 import org.telscenter.pas.steps.actions.DialogSaveAction;
17 import org.telscenter.pas.ui.beans.issueReporter.Issue;
18 import org.telscenter.pas.ui.beans.issueReporter.IssueUI;
19 import org.telscenter.pas.ui.dialog.PasDialogManager;
20 import org.telscenter.pas.ui.dialog.PasIssueReporterConfirmDialogUI;
21
22 public class ReportIssueAction extends DialogSaveAction {
23
24 private IssueUI issueUI;
25
26 private boolean wasSent = false;
27
28 protected Issue currentIssue;
29
30 public ReportIssueAction(ImageIcon imageIcon) {
31 super(imageIcon);
32 }
33
34 public ReportIssueAction(String string, IssueUI issueUI) {
35 super(string);
36 this.issueUI = issueUI;
37 }
38
39 public ReportIssueAction(IssueUI issueUI) {
40 super(Messages.getString("ReportIssueAction.action_name"));
41 this.issueUI = issueUI;
42 }
43
44 public void actionPerformed(ActionEvent e) {
45 makeIssue();
46 boolean result = submitIssueEmail();
47 if (result == true) {
48 hideRootDialog(e.getSource());
49 }
50 }
51
52 public void makeIssue() {
53 currentIssue = issueUI.getCurrentIssue();
54 }
55
56 public boolean submitIssueEmail() {
57
58
59 boolean debug = false;
60 final String SMTP_HOST_NAME = Messages.getString("ReportIssueAction.0");
61 final String SMTP_PORT = Messages.getString("ReportIssueAction.1");
62 final String emailFromAddress = Messages.getString("ReportIssueAction.2");
63 final String SSL_FACTORY = Messages.getString("ReportIssueAction.3");
64 final String username = Messages.getString("ReportIssueAction.4");
65 final String password = Messages.getString("ReportIssueAction.5");
66 final String[] sendTo = { Messages.getString("ReportIssueAction.6") };
67 final String mailDebug = Messages.getString("ReportIssueAction.7");
68 final String fallback = Messages.getString("ReportIssueAction.8");
69 final String auth = Messages.getString("ReportIssueAction.9");
70 Properties props = new Properties();
71
72 props.put("mail.smtp.host", SMTP_HOST_NAME);
73 props.put("mail.smtp.auth", auth);
74 props.put("mail.debug", mailDebug);
75 props.put("mail.smtp.port", SMTP_PORT);
76 props.put("mail.smtp.socketFactory.port", SMTP_PORT);
77 props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
78 props.put("mail.smtp.socketFactory.fallback", fallback);
79
80 Session mailSession = Session.getDefaultInstance(props,
81 new javax.mail.Authenticator() {
82
83 protected PasswordAuthentication getPasswordAuthentication() {
84 return new PasswordAuthentication(username, password);
85 }
86 });
87
88 mailSession.setDebug(debug);
89 PasIssueReporterConfirmDialogUI ui = new PasIssueReporterConfirmDialogUI();
90 try {
91
92 Message msg = new MimeMessage(mailSession);
93 msg.setFrom(new InternetAddress(emailFromAddress));
94 InternetAddress[] sendToAddress = { new InternetAddress(sendTo[0]) };
95 msg.setRecipients(Message.RecipientType.TO, sendToAddress);
96
97 msg.setSubject(Messages
98 .getString("ReportIssueAction.email.subject"));
99 msg.setSentDate(new Date());
100
101
102 msg.setText(currentIssue.toString());
103
104 Transport.send(msg);
105
106 ui.setMessage(Messages.getString("ReportIssueAction.sent"));
107
108 wasSent = true;
109 } catch (Exception e) {
110 ui.setMessage(Messages.getString("ReportIssueAction.error"));
111 e.printStackTrace();
112 wasSent = false;
113 } finally {
114 PasDialogManager.showPasMessageDialog("", ui.createDialogPanel(),
115 null);
116 }
117 return wasSent;
118 }
119
120 }