[LIB] [v1.4.1] SMTP-Email - Send Emails with your plugin

Discussion in 'Resources' started by GermanCoding, May 18, 2014.

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

    GermanCoding

    Maybe because gmail deactivated the unencrypted smtp and switched to only esmtp with encryption? I will check that later.
     
  2. Offline

    GermanCoding

    CoderRyan
    I found this:
    So, it seems like gmail deactivated esmtp/smtp at port 25 and we have to use the SSL/TLS ports (465/587). I will update the source code and add a notice for gmail.
     
  3. Offline

    MineStein

    I am having problems. I this a correct usage?
    Code:java
    1. package me.minestein.Emailer;
    2.  
    3. import org.bukkit.command.Command;
    4. import org.bukkit.command.CommandSender;
    5. import org.bukkit.plugin.java.JavaPlugin;
    6.  
    7. public class Core extends JavaPlugin {
    8.  
    9. @Override
    10. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    11.  
    12. if (cmd.getName().equalsIgnoreCase("email")) {
    13. if (args.length == 0) {
    14. sender.sendMessage("ยง4Specify a valid e-mail address.");
    15. return true;
    16. }
    17.  
    18. String emailTo = args[0];
    19. SMTP.Email email = SMTP.createEmptyEmail();
    20. email.add("Content-Type", "text/html"); //Headers for the email (useful for html) you do not have to set them)
    21. email.from("You", "[email][email protected][/email]"); //The sender of the email.
    22. email.to("Me", "[email][email protected][/email]"); //The recipient of the email.
    23. email.subject("A subject"); //Subject of the email
    24. email.body("Content of the email. Encoded in quoted-printable. You can use control \n characters or html if you set the header");
    25.  
    26. SMTP.sendEmail(
    27. "smtp.gmail.com", //Address of the smtp server. In many cases you can set it to null.
    28. "[email][email protected][/email]", //Your email (Used for login at the smtp server)
    29. "*****", //Your password (Used for login at the smtp server, will be send encrypted to the server)
    30. email, //Email object to send.
    31. true); //Debug mode. If true the console logs the whole connection (output & input)
    32. }
    33.  
    34. return true;
    35. }
    36. }
    37.  
     
  4. Offline

    GermanCoding

    MineStein
    See my last post about gmail. Gmail is only reachable when you use "smtp.gmail.com:465", you used "smtp.gmail.com" and this leads the library to use the standart port 25. Gmail is not longer reachable at port 25.
     
  5. Offline

    MineStein

  6. Offline

    Tommy Raids

    @GermanCoding Any reason why when using a command to send an email, it laggs the server?
     
  7. Offline

    GermanCoding

    As I said in the description, it is recommended to call the sendEmail() function on a async thread. Here is a little example:

    Code:
    new Thread(new Runnable() {
              
                @Override
                public void run() {
                    SMTP.Email email = SMTP.createEmptyEmail();
                    // All the email stuff here
                    SMTP.sendEmail(smtpServer, email, password, mail, debug);
                }
            }).start();
    This will execute the code on a new thread and will not freeze the main/bukkit thread.

    (Note: You also can create "Async Tasks" with Bukkit's Scheduler Service)

    Sending an email costs some time, usually a few seconds. It depends on your host system, your internet connection and so on.
     
    Tommy Raids likes this.
  8. Offline

    Tommy Raids

    Sorry for the trouble, great lib! Thanks so much man. :D
     
    GermanCoding likes this.
  9. Offline

    GermanCoding

    A little update to 1.4.1.
    quoted-printable was not correctly decoded if Content-Type is not set. Content-Type is now set by default to text/plain.
     
Thread Status:
Not open for further replies.

Share This Page