Асинхронная рассылка.
This commit is contained in:
5
.idea/workspace.xml
generated
5
.idea/workspace.xml
generated
@@ -8,10 +8,7 @@
|
|||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="e42177c3-2328-4b27-8a01-35779b2beb99" name="Default Changelist" comment="">
|
<list default="true" id="e42177c3-2328-4b27-8a01-35779b2beb99" name="Default Changelist" comment="">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/SapforTestingSystem/Json/SapforTasksResults_json.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/SapforTestingSystem/Json/SapforTasksResults_json.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/Repository/RepositoryServer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Repository/RepositoryServer.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/SapforTestingSystem/SapforTasksPackage/SapforTasksPackage.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/SapforTestingSystem/SapforTasksPackage/SapforTasksPackage.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/SapforTestingSystem/SapforTasksPackage/SapforTasksPackageInterface.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/SapforTestingSystem/SapforTasksPackage/SapforTasksPackageInterface.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/Visual_DVM_2021/UI/Main/SapforPackagesComparisonForm.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Visual_DVM_2021/UI/Main/SapforPackagesComparisonForm.java" afterDir="false" />
|
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
|||||||
@@ -82,73 +82,81 @@ public abstract class RepositoryServer<D extends Database> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void Email(EmailMessage message_in, File... directAttachements) throws Exception {
|
public void Email(EmailMessage message_in, File... directAttachements) throws Exception {
|
||||||
System.out.println("EMAIL STARTED");
|
Thread thread = new Thread(() -> {
|
||||||
Properties props = new Properties();
|
System.out.println("EMAIL THREAD STARTED");
|
||||||
props.put("mail.smtp.host", Global.properties.SMTPHost);
|
try {
|
||||||
props.put("mail.smtp.auth", "true");
|
Properties props = new Properties();
|
||||||
props.put("mail.smtp.port", String.valueOf(Global.properties.SMTPPort));
|
props.put("mail.smtp.host", Global.properties.SMTPHost);
|
||||||
props.put("mail.smtp.socketFactory.port", String.valueOf(Global.properties.MailSocketPort));
|
props.put("mail.smtp.auth", "true");
|
||||||
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
|
props.put("mail.smtp.port", String.valueOf(Global.properties.SMTPPort));
|
||||||
props.put("mail.smtp.connectiontimeout", String.valueOf(Global.properties.SocketTimeout));
|
props.put("mail.smtp.socketFactory.port", String.valueOf(Global.properties.MailSocketPort));
|
||||||
props.put("mail.smtp.timeout", String.valueOf(Global.properties.SocketTimeout));
|
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
|
||||||
props.put("mail.smtp.writetimeout", String.valueOf(Global.properties.SocketTimeout));
|
props.put("mail.smtp.connectiontimeout", String.valueOf(Global.properties.SocketTimeout));
|
||||||
//------------------------------
|
props.put("mail.smtp.timeout", String.valueOf(Global.properties.SocketTimeout));
|
||||||
LinkedHashMap<String, File> innerFiles = new LinkedHashMap<>();
|
props.put("mail.smtp.writetimeout", String.valueOf(Global.properties.SocketTimeout));
|
||||||
for (String aName : message_in.files.keySet()) {
|
//------------------------------
|
||||||
File f = Utils.getTempFileName(aName);
|
LinkedHashMap<String, File> innerFiles = new LinkedHashMap<>();
|
||||||
Utils.unpackFile(message_in.files.get(aName), f);
|
for (String aName : message_in.files.keySet()) {
|
||||||
innerFiles.put(aName, f);
|
File f = Utils.getTempFileName(aName);
|
||||||
}
|
Utils.unpackFile(message_in.files.get(aName), f);
|
||||||
Vector<String> targets_ = new Vector<>();
|
innerFiles.put(aName, f);
|
||||||
targets_.add(Constants.MailAddress); //себе.
|
|
||||||
targets_.addAll(message_in.targets);
|
|
||||||
//------------------------------
|
|
||||||
Session session = Session.getDefaultInstance(props,
|
|
||||||
new Authenticator() {
|
|
||||||
@Override
|
|
||||||
protected PasswordAuthentication getPasswordAuthentication() {
|
|
||||||
return new PasswordAuthentication(
|
|
||||||
Constants.MailAddress,
|
|
||||||
Constants.MailPassword);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
for (String target : targets_) {
|
|
||||||
System.out.println("target=" + target);
|
|
||||||
if (needsEmail(target)) {
|
|
||||||
System.out.println("needs email");
|
|
||||||
try {
|
|
||||||
MimeMessage message = new MimeMessage(session);
|
|
||||||
message.setFrom(new InternetAddress(Constants.MailAddress));
|
|
||||||
message.setRecipients(Message.RecipientType.CC, InternetAddress.parse(target));
|
|
||||||
message.setSubject(message_in.subject);
|
|
||||||
Multipart multipart = new MimeMultipart();
|
|
||||||
MimeBodyPart textBodyPart = new MimeBodyPart();
|
|
||||||
textBodyPart.setText(message_in.text);
|
|
||||||
multipart.addBodyPart(textBodyPart);
|
|
||||||
for (String aName : innerFiles.keySet()) {
|
|
||||||
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
|
|
||||||
DataSource source = new FileDataSource(innerFiles.get(aName));
|
|
||||||
attachmentBodyPart.setDataHandler(new DataHandler(source));
|
|
||||||
attachmentBodyPart.setFileName(aName);
|
|
||||||
multipart.addBodyPart(attachmentBodyPart);
|
|
||||||
}
|
|
||||||
for (File f : directAttachements) {
|
|
||||||
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
|
|
||||||
DataSource source = new FileDataSource(f);
|
|
||||||
attachmentBodyPart.setDataHandler(new DataHandler(source));
|
|
||||||
attachmentBodyPart.setFileName(f.getName());
|
|
||||||
multipart.addBodyPart(attachmentBodyPart);
|
|
||||||
}
|
|
||||||
message.setContent(multipart);
|
|
||||||
Transport.send(message);
|
|
||||||
System.out.println("message sent");
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
Print(ex.getMessage());
|
|
||||||
}
|
}
|
||||||
} else System.out.println("does not need email");
|
Vector<String> targets_ = new Vector<>();
|
||||||
}
|
targets_.add(Constants.MailAddress); //себе.
|
||||||
System.out.println("EMAIL ENDED");
|
targets_.addAll(message_in.targets);
|
||||||
|
//------------------------------
|
||||||
|
Session session = Session.getDefaultInstance(props,
|
||||||
|
new Authenticator() {
|
||||||
|
@Override
|
||||||
|
protected PasswordAuthentication getPasswordAuthentication() {
|
||||||
|
return new PasswordAuthentication(
|
||||||
|
Constants.MailAddress,
|
||||||
|
Constants.MailPassword);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
for (String target : targets_) {
|
||||||
|
System.out.println("target=" + target);
|
||||||
|
if (needsEmail(target)) {
|
||||||
|
System.out.println("needs email");
|
||||||
|
try {
|
||||||
|
MimeMessage message = new MimeMessage(session);
|
||||||
|
message.setFrom(new InternetAddress(Constants.MailAddress));
|
||||||
|
message.setRecipients(Message.RecipientType.CC, InternetAddress.parse(target));
|
||||||
|
message.setSubject(message_in.subject);
|
||||||
|
Multipart multipart = new MimeMultipart();
|
||||||
|
MimeBodyPart textBodyPart = new MimeBodyPart();
|
||||||
|
textBodyPart.setText(message_in.text);
|
||||||
|
multipart.addBodyPart(textBodyPart);
|
||||||
|
for (String aName : innerFiles.keySet()) {
|
||||||
|
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
|
||||||
|
DataSource source = new FileDataSource(innerFiles.get(aName));
|
||||||
|
attachmentBodyPart.setDataHandler(new DataHandler(source));
|
||||||
|
attachmentBodyPart.setFileName(aName);
|
||||||
|
multipart.addBodyPart(attachmentBodyPart);
|
||||||
|
}
|
||||||
|
for (File f : directAttachements) {
|
||||||
|
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
|
||||||
|
DataSource source = new FileDataSource(f);
|
||||||
|
attachmentBodyPart.setDataHandler(new DataHandler(source));
|
||||||
|
attachmentBodyPart.setFileName(f.getName());
|
||||||
|
multipart.addBodyPart(attachmentBodyPart);
|
||||||
|
}
|
||||||
|
message.setContent(multipart);
|
||||||
|
Transport.send(message);
|
||||||
|
System.out.println("message sent");
|
||||||
|
} catch (Exception ex) {
|
||||||
|
System.out.println("Исключение во время отправки сообщения абоненту " + Utils.Brackets(target));
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
} else System.out.println("does not need email");
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
System.out.println("Исключение во время выполнения рассылки.");
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
System.out.println("EMAIL THREAD ENDED");
|
||||||
|
});
|
||||||
|
thread.start();
|
||||||
}
|
}
|
||||||
public boolean needsEmail(String email) {
|
public boolean needsEmail(String email) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user