mirror of
https://github.com/Hizenberg469/secure_mailer.git
synced 2026-04-19 16:52:24 +03:00
Sent Folder resolved
This commit is contained in:
@@ -144,6 +144,7 @@ public class ValidatorClient {
|
|||||||
this.emlHash = (this.emlHash).substring(0, 100);
|
this.emlHash = (this.emlHash).substring(0, 100);
|
||||||
|
|
||||||
System.out.println("Eml Hash : "+this.emlHash);
|
System.out.println("Eml Hash : "+this.emlHash);
|
||||||
|
System.out.println("Eml Hash size : "+this.emlHash.length());
|
||||||
|
|
||||||
String[] data = new String[] {
|
String[] data = new String[] {
|
||||||
this.emlHash
|
this.emlHash
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ import javafx.concurrent.Task;
|
|||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
import javax.mail.Folder;
|
||||||
|
import javax.mail.Session;
|
||||||
|
import javax.mail.Store;
|
||||||
|
|
||||||
public class EmailSendingService extends Service<Void> {
|
public class EmailSendingService extends Service<Void> {
|
||||||
|
|
||||||
private EmailAccount emailAccount;
|
private EmailAccount emailAccount;
|
||||||
@@ -57,7 +62,7 @@ public class EmailSendingService extends Service<Void> {
|
|||||||
protected Void call() throws Exception {
|
protected Void call() throws Exception {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
System.out.println("From email id : "+emailAccount.getAddress());
|
// System.out.println("From email id : "+emailAccount.getAddress());
|
||||||
MimeMessage mimeMessage = new MimeMessage(emailAccount.getSession());
|
MimeMessage mimeMessage = new MimeMessage(emailAccount.getSession());
|
||||||
mimeMessage.setFrom(new InternetAddress(emailAccount.getAddress()+"@peachy.in.net"));
|
mimeMessage.setFrom(new InternetAddress(emailAccount.getAddress()+"@peachy.in.net"));
|
||||||
mimeMessage.addRecipients(Message.RecipientType.TO, recipient);
|
mimeMessage.addRecipients(Message.RecipientType.TO, recipient);
|
||||||
@@ -96,6 +101,9 @@ public class EmailSendingService extends Service<Void> {
|
|||||||
emailAccount.getPassword());
|
emailAccount.getPassword());
|
||||||
transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
|
transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
|
||||||
transport.close();
|
transport.close();
|
||||||
|
|
||||||
|
storeInSentFolder("peachy.in.net", emailAccount.getAddress(), emailAccount.getPassword(), mimeMessage);
|
||||||
|
|
||||||
} catch(MessagingException e) {
|
} catch(MessagingException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -105,4 +113,54 @@ public class EmailSendingService extends Service<Void> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static void storeInSentFolder(String imapHost, String username, String password, MimeMessage message) {
|
||||||
|
// IMAP server properties
|
||||||
|
Properties imapProps = new Properties();
|
||||||
|
imapProps.put("mail.store.protocol", "imaps");
|
||||||
|
imapProps.put("mail.imap.host", imapHost);
|
||||||
|
imapProps.put("mail.imap.port", "993");
|
||||||
|
imapProps.put("mail.imap.ssl.enable", "true"); // Use SSL for IMAP
|
||||||
|
|
||||||
|
imapProps.setProperty("mail.mime.encodeparameters", "true");
|
||||||
|
// properties.setProperty("mail.mime.decodeparameters","true");
|
||||||
|
imapProps.setProperty("mail.mime.encodefilename", "true");
|
||||||
|
// properties.setProperty("mail.mime.decodefilename","true");
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Connect to the IMAP store
|
||||||
|
Session session = Session.getDefaultInstance(imapProps);
|
||||||
|
Store store = session.getStore("imaps");
|
||||||
|
store.connect(username, password);
|
||||||
|
|
||||||
|
// Open the "Sent" folder
|
||||||
|
Folder sentFolder = store.getFolder("Sent"); // Adjust based on provider's folder name
|
||||||
|
if (!sentFolder.exists()) {
|
||||||
|
sentFolder.create(Folder.HOLDS_MESSAGES);
|
||||||
|
}
|
||||||
|
sentFolder.open(Folder.READ_WRITE);
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
sentFolder.appendMessages(new Message[]{message});
|
||||||
|
// Message[] msgs = folder.getMessages();
|
||||||
|
//message.setFlag(FLAGS.Flag.RECENT, true);
|
||||||
|
System.out.println("Msg send and saved ....");
|
||||||
|
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
System.out.println("error processing message " + ignore.getMessage());
|
||||||
|
} finally {
|
||||||
|
store.close();
|
||||||
|
// folder.close(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the folder and store connection
|
||||||
|
sentFolder.close(false);
|
||||||
|
store.close();
|
||||||
|
|
||||||
|
} catch (MessagingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -54,10 +54,12 @@ public class MessageRendererService extends Service<Object>{
|
|||||||
String contentType = message.getContentType();
|
String contentType = message.getContentType();
|
||||||
if(isSimpleType(contentType)){
|
if(isSimpleType(contentType)){
|
||||||
|
|
||||||
if( emailMessage.getIsAuthenticated() )
|
if( emailMessage.getIsAuthenticated() ) {
|
||||||
stringBuffer.append(message.getContent().toString());
|
stringBuffer.append(message.getContent().toString());
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
stringBuffer.append(encryptMessage(message.getContent().toString()));
|
stringBuffer.append(encryptMessage(message.getContent().toString()));
|
||||||
|
}
|
||||||
|
|
||||||
} else if (isMultipartType(contentType)) {
|
} else if (isMultipartType(contentType)) {
|
||||||
Multipart multipart = (Multipart) message.getContent();
|
Multipart multipart = (Multipart) message.getContent();
|
||||||
@@ -71,10 +73,12 @@ public class MessageRendererService extends Service<Object>{
|
|||||||
String contentType = bodyPart.getContentType();
|
String contentType = bodyPart.getContentType();
|
||||||
if (isSimpleType(contentType)) {
|
if (isSimpleType(contentType)) {
|
||||||
|
|
||||||
if( emailMessage.getIsAuthenticated() )
|
if( emailMessage.getIsAuthenticated() ) {
|
||||||
stringBuffer.append(bodyPart.getContent().toString());
|
stringBuffer.append(bodyPart.getContent().toString());
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
stringBuffer.append(encryptMessage(bodyPart.getContent().toString()));
|
stringBuffer.append(encryptMessage(bodyPart.getContent().toString()));
|
||||||
|
}
|
||||||
|
|
||||||
} else if (isMultipartType(contentType)){
|
} else if (isMultipartType(contentType)){
|
||||||
Multipart multipart2 = (Multipart) bodyPart.getContent();
|
Multipart multipart2 = (Multipart) bodyPart.getContent();
|
||||||
@@ -91,11 +95,12 @@ public class MessageRendererService extends Service<Object>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSimpleType(String contentType) {
|
private boolean isSimpleType(String contentType) {
|
||||||
if(contentType.contains("TEXT/HTML") ||
|
if(contentType.contains("TEXT/HTML") ||
|
||||||
contentType.contains("mixed") ||
|
|
||||||
contentType.contains("text")) {
|
contentType.contains("text")) {
|
||||||
return true;
|
return true;
|
||||||
} else return false;
|
} else return false;
|
||||||
|
|
||||||
|
// contentType.contains("mixed") ||
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isMultipartType(String contentType) {
|
private boolean isMultipartType(String contentType) {
|
||||||
|
|||||||
Reference in New Issue
Block a user