Send emails

Discussion in 'Plugin Development' started by Permeer, Mar 6, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Permeer

    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
     
  2. Offline

    Goblom

    It throws NoClassDefFoundError because you didnt shade the JavaMail API into your plugin.
     
  3. Offline

    Skionz

  4. Offline

    Permeer

    @Skionz Nothing happens (Tried port 20, 587 and 465)

    Code (open)
    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;
        }
     
  5. Offline

    Skionz

    @Permeer Where are you invoking it?
     
  6. Offline

    Permeer

    @Skionz The console msgs are sent, but the email is not sent. And im invoking it here > < * And it is invoked at AsyncPlayerChatEvent.*

    Code (open)
    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();
        }
     
    Last edited: Mar 6, 2015
  7. Offline

    Evaluations

    Add the source of JavaMail in to your plugin, if you can't figure out how to add it as an external jar.
     
  8. Offline

    Permeer

  9. Offline

    Evaluations

    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.
     
  10. Offline

    Permeer

    @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
     
  11. Offline

    Evaluations

    Just use maven. It'll be much easier
     
Thread Status:
Not open for further replies.

Share This Page