Skip to content

Commit 5af2d8b

Browse files
committed
Minor changes.
1 parent 911c862 commit 5af2d8b

File tree

5 files changed

+65
-26
lines changed

5 files changed

+65
-26
lines changed

.project

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22
<projectDescription>
33
<name>JavaSMTPService</name>
44
<comment></comment>
5-
<projects>
6-
</projects>
5+
<projects/>
6+
<natures>
7+
<nature>org.eclipse.jdt.core.javanature</nature>
8+
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
9+
</natures>
710
<buildSpec>
811
<buildCommand>
912
<name>org.eclipse.jdt.core.javabuilder</name>
10-
<arguments>
11-
</arguments>
13+
<arguments/>
1214
</buildCommand>
1315
<buildCommand>
1416
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
15-
<arguments>
16-
</arguments>
17+
<arguments/>
1718
</buildCommand>
1819
</buildSpec>
19-
<natures>
20-
<nature>org.eclipse.jdt.core.javanature</nature>
21-
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
22-
</natures>
20+
<linkedResources/>
21+
<filteredResources/>
2322
</projectDescription>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#
2-
#Thu Jun 20 18:47:21 CDT 2019
2+
#Mon Jul 08 13:40:18 CDT 2019
33
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
44
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
55
eclipse.preferences.version=1
6-
org.eclipse.jdt.core.compiler.source=1.7
76
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
7+
org.eclipse.jdt.core.compiler.source=1.7
88
org.eclipse.jdt.core.compiler.compliance=1.7

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
1-
# Java-SMTP-Standalone-Service
1+
# Java SMTP Standalone Service
2+
3+
This SMTP Service was made as an alternative use of local SMTP commands, like when your application server hasn't commands to execute a SMTP service or you don't had permission to install 3rd party software.
4+
5+
6+
## How to run
7+
8+
This is a simple Java Standalone application, so you only need Java 1.7+ installed on your environment to execute it. The command to do it is the next:
9+
10+
java -jar <pathToJar>/JavaSMTPService.jar
11+
12+
By default the jar search for the default configuration file called "defaultSMTP.conf", to create it use the next command and set all information needed to call a SMTP Service:
13+
14+
java -jar <pathToJar>/JavaSMTPService.jar configure
15+
16+
In case you want to use your own configuration file you have to send the path of the file ypu want to use:
17+
18+
java -jar <pathToJar>/JavaSMTPService.jar /path/to/configure/file.conf
19+
20+
## Make a Configure File
21+
22+
If you don't want to use the command to make a configure file, you have to respect the next structure of the file:
23+
24+
- SMTP_HOST PORT
25+
- TO\_EMAIL,TO\_EMAIL2,...``<space>``[TO\_EMAIL\_CC,TO\_EMAIL\_CC2,...]``<space>``[TO\_EMAIL\_BCC,TO\_EMAIL\_BCC2,...]
26+
- FROM_EMAIL PASSWORD
27+
- TLS|SSL|NONE <= Only one of this options
28+
- FROM_NAME
29+
- SUBJECT
30+
- BODY_MESSAGE
31+
- [ATTACHMENT,ATTACHMENT2,...]
32+
33+
**NOTE:** Attributes in brackets **[ ]** are optional.
34+
35+
## How it works
36+
37+
You need to execute the jar from the application you need to use a SMTP service, the jar will read the configuration file and invoke a SMTP service inside and send the email with the registered information inside the file. The jar will return an exit code 0 if email was successfully send it or an error code and message error like this:
38+
39+
- 101 - File <fileName> not found.
40+
- 102 - I/O Error.
41+
- 103 - Mail not sent + error msg.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ task fatJar(type: Jar) {
3434
'Implementation-Version': '1.0',
3535
'Main-Class': 'com.bahamut1797.smtp.Main'
3636
}
37-
baseName = project.name + '-all'
37+
baseName = project.name
3838
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
3939
with jar
4040
}

src/main/java/com/bahamut1797/smtp/Main.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ public static void main(String[] args) {
4343
if (!smtpFile.exists()) {
4444
System.out.println("File \"defaultSMTP.conf\" not found. Run with \"configure\" command to create it.");
4545
System.out.println("Run \"help\" command for more information.");
46-
System.exit(107);
46+
System.exit(101);
4747
}
4848

4949
// Run the service
5050
sendMail(smtpFile);
5151
} else {
5252
// HELP Command
5353
if (args[0].equalsIgnoreCase("help")) {
54-
System.out.println("Read a file <filePaht> as a parameter, if you omitted, reads the file created by \"configure\" command called \"defaultSMTP.conf\".");
54+
System.out.println("Read a file <filePath> as a parameter, if you omitted, reads the file created by \"configure\" command called \"defaultSMTP.conf\".");
5555
System.out.println("The configuration parameters for SMTP comunication file are:");
5656
System.out.println("SMTP_HOST PORT");
5757
System.out.println("TO_EMAIL,TO_EMAIL2,...<space>[TO_EMAIL_CC,TO_EMAIL_CC2,...]<space>[TO_EMAIL_BCC,TO_EMAIL_BCC2,...]");
@@ -67,9 +67,9 @@ public static void main(String[] args) {
6767
System.out.println("configure\tAn assistant to help you to create a configuration file for SMTP service.");
6868
System.out.println("");
6969
System.out.println("Exit error codes:");
70-
System.out.println("107 - File <fileName> not found.");
71-
System.out.println("108 - I/O Error");
72-
System.out.println("110 - Mail not sent + error msg");
70+
System.out.println("101 - File <fileName> not found.");
71+
System.out.println("102 - I/O Error");
72+
System.out.println("103 - Mail not sent - <error_msg>");
7373

7474
System.exit(0);
7575
} else if (args[0].equalsIgnoreCase("configure")) { // CONFIGURE Command
@@ -78,7 +78,7 @@ public static void main(String[] args) {
7878
File smtpFile = new File(args[0]);
7979
if (!smtpFile.exists()) {
8080
System.out.println("File \"" + args[0] + "\" not found.");
81-
System.exit(107);
81+
System.exit(101);
8282
}
8383

8484
// Run the service
@@ -192,7 +192,7 @@ private static void createConfigureFile() {
192192

193193
} catch (IOException e) {
194194
System.out.println("I/O Error \n" + e.getMessage());
195-
System.exit(108);
195+
System.exit(102);
196196
}
197197
}
198198

@@ -282,10 +282,10 @@ protected PasswordAuthentication getPasswordAuthentication() {
282282

283283
} catch (FileNotFoundException e) {
284284
System.out.println("File \"" + smtpFile.getName() + "\" not found.");
285-
System.exit(107);
285+
System.exit(101);
286286
} catch (IOException e) {
287287
System.out.println("I/O Error: \n" + e.getMessage());
288-
System.exit(108);
288+
System.exit(102);
289289
}
290290
}
291291

@@ -327,7 +327,7 @@ private static void sendEmail(Session session, String toEmail, String toEmailCC,
327327
Transport.send(msg);
328328
} catch (MessagingException | UnsupportedEncodingException e) {
329329
System.out.println("Error: Mail not sent - " + e.getMessage());
330-
System.exit(110);
330+
System.exit(103);
331331
}
332332
}
333333

@@ -394,10 +394,10 @@ private static void sendAttachmentEmail(Session session, String toEmail, String
394394

395395
} catch (MessagingException e) {
396396
System.out.println("Error: Mail not sent - " + e.getMessage());
397-
System.exit(110);
397+
System.exit(103);
398398
} catch (UnsupportedEncodingException e) {
399399
System.out.println("Error: Mail not sent - " + e.getMessage());
400-
System.exit(110);
400+
System.exit(103);
401401
}
402402
}
403403

0 commit comments

Comments
 (0)