[LIB] Email - Send Emails From Plugins!

Discussion in 'Resources' started by Icyene, Sep 21, 2012.

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


    Quite recently I tried making my plugin send emails to server owners, as part of a sort of daily-log type thing. However, as with most things, the best way isn't the easiest. Java has an API called JavaMail, which makes email sending easy-peasy. However, it comes in the javax.mail.* package, which is an OPTIONAL component of J2SE. Meaning, you aren't guaranteed its there. If you do not care about this, zeeveener wrote a nice tutorial on using JavaMail for this here.

    Here is my offering to fill in this gap. A very lightweight emailing API, which supports Yahoo! and GMail. Hotmail is not supported.

    This API, while limited, makes up with the simplicity of it. To send an email, its as simple as:

    2. Email email = new Email(Provider.GMAIL, "myEmail-at-gmail.com", "password");
    3. email.sendEmail("toEmail-at-email.com", "subject", "content");

    And with that, toEmail will receive an email with titled "subject" with the content being "content". Supported providers are GMAIL and YAHOO. Fun fact: Yahoo allows you to authenticate with a GMail account, and will allow you to send an email. The same is not true for Provider.GMAIL; it will refuse a Yahoo account.

    • Doesn't work with Hotmail accounts. Even sending through Yahoo SMTP will fail.
    • Emails sent through Provider.YAHOO will have a (unknown sender) as the person who sent it. It is a bug I am working to resolve, but can be used for anonymous emails.
    • Sending through Yahoo is much faster than sending through GMail, so use it if you don't mine an anonymous sender.
    >> Get Emailer <<
  2. Looks cool, may use this!
  3. Offline


    Interesting. I foresee this being used a lot in the future.
  4. Offline


    I guess you could just create a Gmail or Yahoo mail account then forward the mail to a Hotmail address if the owner was that fussed.
  5. Offline


    I think that this needs to be changed a bit. There should be a constructor for the Email account.

    Email email = new Email(Provider, Email, Password);
    email.sendEmail(toEmail, Subject, Message);
    Icyene likes this.
  6. Offline



    Fair point. I've changed the Email class to reflect this, and I've also added some minor improvements in terms of formatting and cleanliness. I'm keeping the code in a Gist now, since syntax tags clobber code formatting.
    zachoooo likes this.
  7. Offline


    Very nice, will definitely be using this!
  8. Offline


    When Yahoo will be fixed, I'll use this :)
  9. Offline


    People DON'T use this for PUBLIC for public plugins. When i decompile u plugin i get u password from u email ;)
    Skyost and KingFaris11 like this.
  10. Offline


    It was never intended for one to store the raw email/password in a plugin. Rather, it should be used with a user-defined email/password read from a configuration file.
    Skyost, TheGreenGamerHD and zachoooo like this.
  11. Offline


    Server admin can create account and write to config password, username etc.

    EDIT: I should've refreshed page before posting xD
  12. Offline


    That is terrible etiquette... and spelling...
    Jamboozlez and KingFaris11 like this.
  13. Offline


    Sorry i know my english isnt good :$
  14. Offline


    Hey this looks really useful but on line 51 I'm getting a warning saying:
    "The method readLine() from the type DataInputStream is deprecated"

    Does anyone know what the method needs to be changed to?
  15. Offline


    Hey, I'm getting a lot of gibberish and I assume it's from the email.
    Here's the part the worries me:
    02.10 01:55:22 [Server] INFO 530 5.7.0 Must issue a STARTTLS command first. dk3sm9352545pbc.32 - gsmtp
    02.10 01:55:22 [Server] INFO 502 5.5.1 Unrecognized command. dk3sm9352545pbc.32 - gsmtp
    02.10 01:55:22 [Server] INFO 502 5.5.1 Unrecognized command. dk3sm9352545pbc.32 - gsmtp
    02.10 01:55:22 [Server] INFO 530 5.7.0 Must issue a STARTTLS command first. dk3sm9352545pbc.32 - gsmtp
    02.10 01:55:22 [Server] INFO 250 mx.google.com at your service
    02.10 01:55:22 [Server] INFO 220 mx.google.com ESMTP dk3sm9352545pbc.32 - gsmtp
  16. Offline


    Yeah im getting this too, hmmmmm
  17. Offline


    Just remove the logging lines from the email class :p
  18. Offline


    You should comment or remove the block at line 49, given that STARTTLS part, I reckon it wouldn't work outright. I don't believe either Yahoo! nor GMail uses crypto, though. At least they didn't when I wrote this; if this has changed since then I'll have to update this library.

    See above; that block isn't truly needed. You could replace it with a BufferedReader, if you do want warnings to get printed to the console.
  19. Offline


    But it's not sending an email?
  20. Offline


    I am not getting any emails.
    Mind explain what "crypto" is?
  21. Offline


    You aren't getting any emails because this library is currently broken.

    Crypto is short for cryptography, which is essentially encryption.

    GMail seems to have changed in the recent past to require encryption of data being sent. I'm almost done updating, and once I am finished this library should be able to be used with any SMTP server.
    Assist likes this.
  22. Awesome, been waiting this for a while. I'm not sure if this has something to do with Google or my connection, but I'm getting java.net.ConnectionException after I attempt to send the email. Also DataInputStream was deprecated for me, so I replaced it with Scanner. Any idea if this would work, or are you going to add a fix for that in the new update?
    1. Scanner scanner = new Scanner(socket.getInputStream());
  23. Offline


    From now on, instead of this library use xiaomao 's SMTP library, which you can find here. It supersedes this library, and supports TLS.
  24. Offline


    How would i use that lib?
  25. Offline


    There's an example at the bottom of the file.
  26. Offline


    Oh yeah thanks!
  27. Offline


    Icyene I know it's not your LIB but do you know how I remove the messages it sends to console when you send an email? It spams the console with the message.
  28. Offline


    Icyene Also that lib stills give me the error that i i have an incorrect email & pass? when i don't...
  29. Offline


    When I try to use yahoo I get this message in the console:

    [22:08:26 INFO]: 220 smtp.mail.yahoo.com ESMTP ready
    [22:08:26 INFO]: 501 5.5.4 Invalid argument
  30. Offline


    Interesting. Possibly going bookmark this for a feature in my plugin that emails inactive players or something...
Thread Status:
Not open for further replies.

Share This Page