0
메일 서버에 연결하여 특정 제목 태그를 검색하고 해당 메일에 응답을 다시 보냅니다 (회신).SMTP 호스트에 연결할 수 없습니다 : localhost, port : 25 - 메일에 REPLYing하는 동안
그러나 나는 다음과 같은 오류가 회신 메시지주고있는 동안 :
Could not connect to SMTP host: localhost, port: 25
을 그 문제는 내가 REPLY를 사용하는 경우에만/FORWARD 곤하는 법이있는 javamail을 사용하고 발생하는 직접 이메일을 보낼 수 있어요.
import java.util.*;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.search.SearchTerm;
import javax.mail.search.SubjectTerm;
public class Mail {
public static void main(String args[]) throws Exception {
Properties properties = System.getProperties();
Session session = Session.getDefaultInstance(properties);
Store store = session.getStore("pop3");
store.connect("smtp.gotouchpoint.com", "username", "password");
Folder folder = store.getFolder("inbox");
//Connect to the current host using the specified username and password.
try {
//Create a Folder object corresponding to the given name.
// Folder folder = store.getFolder("INBOX");
// Open the Folder.
folder.open(Folder.READ_WRITE);
SearchTerm st1 =new SubjectTerm("**NEW-TICKET**");
Message[] message = folder.search(st1);
//Message[] message = folder.getMessages();
// Create a reply message
for (int i = 0; i < message.length; i++) {
System.out.println("------------ Message " + (i + 1) + " ------------");
System.out.println("SentDate : " + message[i].getSentDate());
System.out.println("From : " + message[i].getFrom()[0]);
System.out.println("Subject : " + message[i].getSubject());
if(message[i].getSubject().equals("**NEW-TICKET**")) {
System.out.println("new-ticket");
Message forward = new MimeMessage(session);
// Fill in header
forward.setSubject("Fwd: " + message[i].getSubject());
forward.setFrom(new InternetAddress(message[i].getFrom()[0].toString()));
forward.addRecipient(Message.RecipientType.TO,
new InternetAddress("[email protected]"));
// Create your new message part
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText("Oiginal message:\n\n");
// Create a multi-part to combine the parts
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// Create and fill part for the forwarded content
messageBodyPart = new MimeBodyPart();
messageBodyPart.setDataHandler(message[i].getDataHandler());
// Add part to multi part
multipart.addBodyPart(messageBodyPart);
// Associate multi-part with message
forward.setContent(multipart);
System.out.println("msg forward ...." +forward.getSubject());
// Send message
Transport.send(forward);
}
}
System.out.println();
folder.close(true);
store.close();
}catch(Exception e) {
e.printStackTrace();
}
}
}