Hello bukkit, community. I just want to know how i can send Emails ? I tried JavaMail API but it returns NoClassDefFoundError. I couldnt figure out how to resolve this. I hope if someone could help me
@Permeer You can open a Socket to a SMPT server and write the information to the output stream. http://www.java2s.com/Code/Java/Network-Protocol/SendingMailUsingSockets.htm
@Skionz Nothing happens (Tried port 20, 587 and 465) Code (Move your mouse to reveal the content) Code (open) Code (close) Code: @SuppressWarnings("resource") public boolean sendE(String host, String from, String to) throws IOException { InetAddress localhost = InetAddress.getLocalHost(); BufferedReader in; PrintWriter out; Socket socket = new Socket("smtp.gmail.com", 465); BufferedReader msg = new BufferedReader(new InputStreamReader( socket.getInputStream())); InputStream inn = socket.getInputStream(); OutputStream outt = socket.getOutputStream(); in = new BufferedReader(new InputStreamReader(inn)); out = new PrintWriter(new OutputStreamWriter(outt), true); if (inn == null || outt == null) { System.out.println("Failed to open streams to socket."); return false; } out.println("HELO " + localhost.getHostName()); out.println("MAIL From:<" + from + ">"); out.println("RCPT TO:<" + to + ">"); String line; while ((line = msg.readLine()) != null) { out.println(line); } System.out.println("."); out.println("."); out.println("QUIT"); return true; }
@Skionz The console msgs are sent, but the email is not sent. And im invoking it here > < * And it is invoked at AsyncPlayerChatEvent.* Code (Move your mouse to reveal the content) Code (open) Code (close) Code: public void finish() { /* * Yaml y = new Yaml(Main.get().getDataFolder().getPath(), "form.yml"); * y.set("" + p.getUniqueId(), true); y.save(); */ p.sendMessage("§a§lVoce completou o formulario."); p.sendMessage("§a§l* §7Nao peça resposta imediata do formulario caso peça\n" + "suas chances diminuirao"); this.p = null; try { sendE("smtp.gmail.com", email, emailf); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } cancel(); }
Add the source of JavaMail in to your plugin, if you can't figure out how to add it as an external jar.
It's one way, but adding it as an external jar is probably the best way. There's a few tutorials on strictly JavaMail showing you how to add the mail.jar in to your project, here on Bukkit. At first I used JavaMail's source to add in to my plugin because I was too lazy, then figured it out how to add it separately in a jar later eventually.
@Evaluations I've tried add it into the build path, import into a lib file(Like some tutorials), create a lib folder in my plugin folder, import it into the project But nothing worked