fix бага с отключенной рассылкой
This commit is contained in:
@@ -80,7 +80,10 @@ public abstract class RepositoryServer<D extends Database> {
|
||||
Log.close();
|
||||
}
|
||||
}
|
||||
protected void checkTargets(EmailMessage message_in) {
|
||||
}
|
||||
public void Email(EmailMessage message_in, File... directAttachements) throws Exception {
|
||||
checkTargets(message_in);
|
||||
Thread thread = new Thread(() -> {
|
||||
System.out.println("EMAIL THREAD STARTED");
|
||||
try {
|
||||
@@ -115,49 +118,46 @@ public abstract class RepositoryServer<D extends Database> {
|
||||
});
|
||||
for (String target : targets_) {
|
||||
System.out.println("target=" + target);
|
||||
if (needsEmail(target)) {
|
||||
System.out.println("needs email");
|
||||
boolean done = false;
|
||||
int attempts = 5;
|
||||
while (!done && (attempts > 0)) {
|
||||
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()) {
|
||||
boolean done = false;
|
||||
int attempts = 5;
|
||||
while (!done && (attempts > 0)) {
|
||||
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) {
|
||||
if (f.exists()) {
|
||||
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
|
||||
DataSource source = new FileDataSource(innerFiles.get(aName));
|
||||
DataSource source = new FileDataSource(f);
|
||||
attachmentBodyPart.setDataHandler(new DataHandler(source));
|
||||
attachmentBodyPart.setFileName(aName);
|
||||
attachmentBodyPart.setFileName(f.getName());
|
||||
multipart.addBodyPart(attachmentBodyPart);
|
||||
}
|
||||
for (File f : directAttachements) {
|
||||
if (f.exists()) {
|
||||
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");
|
||||
done = true;
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Исключение во время отправки сообщения абоненту " + Utils.Brackets(target));
|
||||
ex.printStackTrace();
|
||||
Utils.sleep(1000);
|
||||
} finally {
|
||||
attempts--;
|
||||
}
|
||||
message.setContent(multipart);
|
||||
Transport.send(message);
|
||||
System.out.println("message sent");
|
||||
done = true;
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Исключение во время отправки сообщения абоненту " + Utils.Brackets(target));
|
||||
ex.printStackTrace();
|
||||
Utils.sleep(1000);
|
||||
} finally {
|
||||
attempts--;
|
||||
}
|
||||
} else System.out.println("does not need email");
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Исключение во время выполнения рассылки.");
|
||||
@@ -167,9 +167,6 @@ public abstract class RepositoryServer<D extends Database> {
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
public boolean needsEmail(String email) {
|
||||
return true;
|
||||
}
|
||||
public boolean canDelete(DBObject object) throws Exception {
|
||||
return true;
|
||||
}
|
||||
@@ -322,7 +319,7 @@ public abstract class RepositoryServer<D extends Database> {
|
||||
}
|
||||
}
|
||||
//--
|
||||
protected Database getDefaultDatabase(){
|
||||
protected Database getDefaultDatabase() {
|
||||
return db;
|
||||
}
|
||||
//--
|
||||
|
||||
Reference in New Issue
Block a user