Email not sending.

Discussion in 'Plugin Development' started by CMG, Oct 4, 2013.

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

    CMG

    Okay, I've been trying to send an email in a plugin and none of the ways iv'e tried are working (ive also tried using the java-mail API too but that didn't work) so i tried using this email API by Icene:

    http://forums.bukkit.org/threads/lib-email-send-emails-from-plugins.101927/#post-1882801

    and im getting this error when im sending an email:

    Code:java
    1. 02.10 01:55:22 [Server] INFO 530 5.7.0 Must issue a STARTTLS command first. dk3sm9352545pbc.32 - gsmtp
    2. 02.10 01:55:22 [Server] INFO 502 5.5.1 Unrecognized command. dk3sm9352545pbc.32 - gsmtp
    3. 02.10 01:55:22 [Server] INFO 502 5.5.1 Unrecognized command. dk3sm9352545pbc.32 - gsmtp
    4. 02.10 01:55:22 [Server] INFO 530 5.7.0 Must issue a STARTTLS command first. dk3sm9352545pbc.32 - gsmtp
    5. 02.10 01:55:22 [Server] INFO 250 mx.google.com at your service
    6. 02.10 01:55:22 [Server] INFO 220 mx.google.com ESMTP dk3sm9352545pbc.32 - gsmtp


    Here is the code:

    MailManager:
    Code:java
    1. package me.CMG.EReg.Util;
    2.  
    3. import java.io.DataInputStream;
    4. import java.io.DataOutputStream;
    5. import java.io.IOException;
    6. import java.net.Socket;
    7.  
    8. public class MailManager {
    9.  
    10. private Provider provider;
    11. private String owner;
    12. private String password;
    13.  
    14. public MailManager(Provider provider, String owner, String password) {
    15. this.provider = provider;
    16. this.owner = owner;
    17. this.password = password;
    18. }
    19.  
    20. @SuppressWarnings("deprecation")
    21. public void sendEmail(String to, String content, String subject, int port) {
    22.  
    23. String HOST = provider.getHost();
    24.  
    25. String PASSWORD = Base64Coder.encodeString(password);
    26. String USER = Base64Coder.encodeString(owner);
    27.  
    28. try {
    29. Socket socket = new Socket(HOST, port);
    30.  
    31. DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
    32. DataInputStream is = new DataInputStream(socket.getInputStream());
    33.  
    34. dos.writeBytes("HELO\r\n");
    35. dos.writeBytes("AUTH LOGIN");
    36. dos.writeBytes("\r\n");
    37. dos.writeBytes(USER);
    38. dos.writeBytes("\r\n");
    39. dos.writeBytes(PASSWORD);
    40. dos.writeBytes("\r\n");
    41. dos.writeBytes("MAIL FROM:<" + owner + ">\r\n");
    42. dos.writeBytes("\r\n");
    43. dos.writeBytes("RCPT TO: <" + to + ">\r\n");
    44. dos.writeBytes("DATA\r\n");
    45. dos.writeBytes("Subject: " + subject + "\r\n");
    46. dos.writeBytes(content);
    47. dos.writeBytes("\r\n.\r\n");
    48. dos.writeBytes("QUIT\r\n");
    49.  
    50. dos.flush();
    51.  
    52. String responseline;
    53. while ((responseline = is.readLine()) != null) {
    54. System.out.println(responseline);
    55. }
    56.  
    57. is.close();
    58. dos.close();
    59. socket.close();
    60. } catch (IOException ex) {
    61. System.err.println(ex);
    62. }
    63. }
    64.  
    65. public void sendEmail(String to, String content, String subject) {
    66. sendEmail(to, content, subject, 25); // Use default port
    67. }
    68.  
    69. public enum Provider {
    70.  
    71. YAHOO("smtp.mail.yahoo.com"),
    72. GMAIL("smtp.gmail.com");
    73. private String host;
    74.  
    75. this.host = host;
    76.  
    77. }
    78.  
    79. public String getHost() {
    80. return host;
    81. }
    82. }
    83.  
    84. /*
    85. * Base 64 encoding implementation from [URL]http://www.source-code.biz/base64coder/java/[/URL]
    86. */
    87. static class Base64Coder {
    88.  
    89. private static final char[] map1 = new char[64];
    90.  
    91. static {
    92. int i = 0;
    93. for (char c = 'A'; c <= 'Z'; c++) {
    94. map1[i++] = c;
    95. }
    96. for (char c = 'a'; c <= 'z'; c++) {
    97. map1[i++] = c;
    98. }
    99. for (char c = '0'; c <= '9'; c++) {
    100. map1[i++] = c;
    101. }
    102. map1[i++] = '+';
    103. map1[i++] = '/';
    104. }
    105. // Mapping table from Base64 characters to 6-bit nibbles.
    106. private static final byte[] map2 = new byte[128];
    107.  
    108. static {
    109. for (int i = 0; i < map2.length; i++) {
    110. map2[I] = -1;[/I]
    111. [I] }[/I]
    112. [I] for (int i = 0; i < 64; i++) {[/I]
    113. [I] map2[map1[I]] = (byte) i;[/I][/I]
    114. [I] }[/I]
    115. [I] }[/I]
    116.  
    117. [I] public static String encodeString(String s) {[/I]
    118. [I] return new String(encode(s.getBytes()));[/I]
    119. [I] }[/I]
    120.  
    121. [I] public static char[] encode(byte[] in) {[/I]
    122. [I] return encode(in, 0, in.length);[/I]
    123. [I] }[/I]
    124.  
    125. [I] public static char[] encode(byte[] in, int iLen) {[/I]
    126. [I] return encode(in, 0, iLen);[/I]
    127. [I] }[/I]
    128.  
    129. [I] public static char[] encode(byte[] in, int iOff, int iLen) {[/I]
    130. [I] int oDataLen = (iLen * 4 + 2) / 3;[/I]
    131. [I] int oLen = ((iLen + 2) / 3) * 4;[/I]
    132. [I] char[] out = new char[oLen];[/I]
    133. [I] int ip = iOff;[/I]
    134. [I] int iEnd = iOff + iLen;[/I]
    135. [I] int op = 0;[/I]
    136. [I] while (ip < iEnd) {[/I]
    137. [I] int i0 = in[ip++] & 0xff;[/I]
    138. [I] int i1 = ip < iEnd ? in[ip++] & 0xff : 0;[/I]
    139. [I] int i2 = ip < iEnd ? in[ip++] & 0xff : 0;[/I]
    140. [I] int o0 = i0 >>> 2;[/I]
    141. [I] int o1 = ((i0 & 3) << 4) | (i1 >>> 4);[/I]
    142. [I] int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6);[/I]
    143. [I] int o3 = i2 & 0x3F;[/I]
    144. [I] out[op++] = map1[o0];[/I]
    145.  
    146. [I] out[op++] = map1[o1];[/I]
    147. [I] out[op] = op < oDataLen ? map1[o2] : '=';[/I]
    148. [I] op++;[/I]
    149. [I] out[op] = op < oDataLen ? map1[o3] : '=';[/I]
    150. [I] op++;[/I]
    151. [I] }[/I]
    152. [I] return out;[/I]
    153. [I] }[/I]
    154.  
    155. [I] private Base64Coder() {[/I]
    156.  
    157. [I] }[/I]
    158. [I] }[/I]
    159. [I]}[/I]


    Sending Email:

    Code:java
    1. MailManager email = new MailManager(Provider.GMAIL, (String)SettingsManager.getManager().getConfig("EReg.Gmail.Email"), (String)SettingsManager.getManager().getConfig("EReg.Gmail.Password"));
    2. email.sendEmail(args[0], "Server-Registration", "Your code is: " + ID + " !");


    Any ideas on why this is happening? Or is there a efficient way of sending an email (simple one with subject and body)?

    Really no replies?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  2. Offline

    The_Doctor_123

    CMG
    A lot of people here probably haven't worked with e-mails in Java.
     
    KingFaris11 likes this.
  3. What he said. ^^
    I think there's a much easier way to send emails, but I don't know how.
     
  4. Offline

    CMG

    Yeah, like i said ive tried using the JavaMail Api but i get the same starttls thingy error :/
     
  5. Offline

    Codisimus

    This isn't the right place to ask this question. I am sent emails from a Bukkit plugin before but I doubt you will fine many (if any) other people who have. Emailing in Java is the same whether it is on a Minecraft server or not so you could expand your search to other sites. I used JavaMail myself. You can look at my source at https://github.com/Codisimus/TextPlayer but I haven't touched it in a while.
     
  6. Offline

    CMG

    Thanks but yeah i know its not just in bukkit but ive searched all over google and all of the Tutorials are the same and are all on JavaMail API.
     
  7. Offline

    Frkinklown

  8. Offline

    Tirelessly

    Why are there carriage returns in your outputstream code?
     
  9. Offline

    Tehmaker

  10. Offline

    MCForger

    Tehmaker
    JDK Alpha and Beta 1995 and the initial release was sometime in 1996 (From what I remember from books).
     
  11. Offline

    DAZ3DNDC0NFUS3D

    Lolwut? Java has been around since 1995
     
  12. Offline

    Tehmaker


    Really? Thought it was around for less haha. I was thinking 7-8 years :p
     
  13. Offline

    Frkinklown

    Tehmaker Tehmaker
    sorry tehmaker, just reading and had to point out your "words of knowledge" "1. If you do not know Java, learn it first"

    lol sorry had to point it out along with java being about 18 years now :p
     
  14. Offline

    Tehmaker


    Lol haha, I know the language, not its history, and origins. For example, I know how to speak french (fluently), but I do not know its origin, who founded it, what the hell happened to put it here haha.
     
Thread Status:
Not open for further replies.

Share This Page