+ try (Socket smtp = new Socket(targetHost, targetPort); PrintWriter out = new PrintWriter(new OutputStreamWriter(smtp.getOutputStream(), "UTF-8")); BufferedReader in = new BufferedReader(new InputStreamReader(smtp.getInputStream(), "UTF-8"));) {
+ readSMTPResponse(in, 220);
+ out.print("HELO www.cacert.org\r\n");
+ out.flush();
+ readSMTPResponse(in, 250);
+ out.print("MAIL FROM:<returns@cacert.org>\r\n");
+ out.flush();
+ readSMTPResponse(in, 250);
+ bits = to.split(",");
+ for (String user : bits) {
+ out.print("RCPT TO:<" + user.trim() + ">\r\n");
+ out.flush();
+ readSMTPResponse(in, 250);
+ }
+ out.print("DATA\r\n");
+ out.flush();
+ readSMTPResponse(in, 250);
+ out.print("X-Mailer: SomeCA.org Website\r\n");
+ // if (array_key_exists("REMOTE_ADDR", $_SERVER)) {
+ // out.print("X-OriginatingIP: ".$_SERVER["REMOTE_ADDR"]."\r\n");
+ // }
+ // TODO
+ SimpleDateFormat emailDate = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss ZZZZ (z)", Locale.ENGLISH);
+ out.print("Date: " + emailDate.format(new Date(System.currentTimeMillis())) + "\r\n");
+ if (errorsto != null) {
+ out.print("Sender: " + errorsto + "\r\n");
+ out.print("Errors-To: " + errorsto + "\r\n");
+ }
+ if (replyto != null) {
+ out.print("Reply-To: " + replyto + "\r\n");
+ } else {
+ out.print("Reply-To: " + from + "\r\n");
+ }
+ out.print("From: support@" + ServerConstants.getWwwHostName().replaceAll("^www.", "") + "\r\n");
+ out.print("To: " + to + "\r\n");
+ if (NON_ASCII.matcher(subject).matches()) {