-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
GroG
committed
Jan 8, 2025
1 parent
2ba5e79
commit 4bf209c
Showing
5 changed files
with
138 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,9 +44,12 @@ public class Email extends Service<EmailConfig> { | |
public Email(String n, String id) { | ||
super(n, id); | ||
} | ||
|
||
Properties props = new Properties(); | ||
|
||
|
||
public Map<String, String> setGmailProps(String user, String password) { | ||
Map<String, String> props = ((EmailConfig) this.config).properties; | ||
public Properties setGmailProps(String user, String password) { | ||
|
||
props.put("mail.smtp.user", user); | ||
props.put("mail.smtp.pass", password); | ||
props.put("mail.smtp.host", "smtp.gmail.com"); | ||
|
@@ -88,11 +91,7 @@ public void sendImage(String to, String imageFile) { | |
*/ | ||
|
||
public void sendMail(String to, String subject, String body, String imageFile) { | ||
EmailConfig config = (EmailConfig) this.config; | ||
|
||
Properties props = new Properties(); | ||
props.putAll(config.properties); | ||
sendTextMail(config.properties.get("mail.smtp.user"), to, subject, body, config.format, null); | ||
sendTextMail((String)props.get("mail.smtp.user"), to, subject, body, config.format, null); | ||
} | ||
|
||
public void sendHtmlMail(String from, String to, String subject, String body, String imageFileName) { | ||
|
@@ -108,9 +107,6 @@ public void sendHtmlMail(String from, String to, String subject, String body, St | |
to = config.to; | ||
} | ||
|
||
Properties props = new Properties(); | ||
props.putAll(config.properties); | ||
|
||
Session session = Session.getDefaultInstance(props); | ||
|
||
// Create a default MimeMessage object. | ||
|
@@ -191,10 +187,6 @@ public void sendHtmlMail(String from, String to, String subject, String body, St | |
|
||
public void sendTextMail(String from, String to, String subject, String body, String format, List<Object> attachments) { | ||
try { | ||
EmailConfig config = (EmailConfig) this.config; | ||
|
||
Properties props = new Properties(); | ||
props.putAll(config.properties); | ||
|
||
Session session = Session.getDefaultInstance(props); | ||
|
||
|
@@ -252,11 +244,11 @@ public static void main(String[] args) { | |
try { | ||
|
||
LoggingFactory.init(Level.INFO); | ||
|
||
Runtime.start("webgui","WebGui"); | ||
Runtime.start("python","Python"); | ||
Email email = (Email) Runtime.start("email", "Email"); | ||
|
||
email.setGmailProps("[email protected]", "xxxxxxxxx"); | ||
email.sendImage("[email protected]", "data/OpenCV/cv-00573.png"); | ||
email.setGmailProps("[email protected]", "XXXXXXXXXX"); | ||
email.sendImage("[email protected]", "data/OpenCV/i01.opencv-00136.png"); | ||
|
||
} catch (Exception e) { | ||
log.error("main threw", e); | ||
|
38 changes: 16 additions & 22 deletions
38
src/main/java/org/myrobotlab/service/config/EmailConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,23 @@ | ||
package org.myrobotlab.service.config; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Email config gets turned into javax email props | ||
*/ | ||
public class EmailConfig extends ServiceConfig { | ||
|
||
@Deprecated /* is supposed to be userfriendly not like a single properties */ | ||
public Map<String,String> properties = new HashMap<>(); | ||
|
||
public String to; // if set sends auto | ||
|
||
public String to; // if set sends auto | ||
public String format = "text/html"; // text/html or text/plain | ||
|
||
// elements in the map | ||
public String user = null; | ||
public String host = null; | ||
public int port = 25; /* 465, 587 */ | ||
public String from = null; | ||
boolean auth = true; | ||
boolean starttls = true; | ||
boolean debug = true; | ||
boolean starttlsRequired = true; | ||
String protocols = "TLSv1.2"; | ||
String socketFactory = "javax.net.ssl.SSLSocketFactory"; | ||
|
||
public String pass = null; | ||
public String user = null; | ||
public String host = null; | ||
public int port = 25; /* 465, 587 */ | ||
public String from = null; | ||
boolean auth = true; | ||
boolean starttls = true; | ||
boolean debug = true; | ||
boolean starttlsRequired = true; | ||
String protocols = "TLSv1.2"; | ||
String socketFactory = "javax.net.ssl.SSLSocketFactory"; | ||
|
||
public String pass = null; | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
src/main/resources/resource/WebGui/app/service/js/EmailGui.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
angular.module("mrlapp.service.EmailGui", []).controller("EmailGuiCtrl", [ | ||
"$scope", | ||
"mrl", | ||
function ($scope, mrl) { | ||
console.info("EmailGuiCtrl") | ||
var _self = this | ||
var msg = this.msg | ||
|
||
// GOOD TEMPLATE TO FOLLOW | ||
this.updateState = function (service) { | ||
$scope.service = service | ||
} | ||
|
||
// init scope variables | ||
$scope.onTime = null | ||
$scope.onEpoch = null | ||
|
||
this.onMsg = function (inMsg) { | ||
let data = inMsg.data[0] | ||
switch (inMsg.method) { | ||
case "onState": | ||
_self.updateState(data) | ||
$scope.$apply() | ||
break | ||
case "onTime": | ||
const date = new Date(data) | ||
$scope.onTime = date.toLocaleString() | ||
$scope.$apply() | ||
break | ||
case "onEpoch": | ||
$scope.onEpoch = data | ||
$scope.$apply() | ||
break | ||
default: | ||
console.error("ERROR - unhandled method " + $scope.name + " " + inMsg.method) | ||
break | ||
} | ||
} | ||
|
||
msg.subscribe("publishTime") | ||
msg.subscribe("publishEpoch") | ||
msg.subscribe(this) | ||
}, | ||
]) |
58 changes: 58 additions & 0 deletions
58
src/main/resources/resource/WebGui/app/service/views/EmailGui.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<br/><br/><br/> | ||
<div class="row"> | ||
<table class="padded-table"> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Value</th> | ||
<th>Actions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr ng-repeat="(key, value) in service.props"> | ||
<td>{{ key }}</td> | ||
<td> | ||
<span ng-if="!editMode[key]">{{ value }}</span> | ||
<input ng-if="editMode[key]" type="text" ng-model="service.props[key]" /> | ||
</td> | ||
<td> | ||
<button ng-click="toggleEdit(key)"> | ||
<span ng-if="!editMode[key]">✏️</span> | ||
<span ng-if="editMode[key]">✔️</span> | ||
</button> | ||
<button ng-click="removeProp(key)">❌</button> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td><input type="text" ng-model="newProp.name" placeholder="New Name" /></td> | ||
<td><input type="text" ng-model="newProp.value" placeholder="New Value" /></td> | ||
<td><button ng-click="addProp()">➕</button></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
|
||
<!-- Email Section --> | ||
<div class="row" style="margin-top: 20px;"> | ||
<!-- Recipient Input --> | ||
<label>To:</label> | ||
<input type="email" ng-model="emailRecipient" style="width: 100%;" placeholder="Recipient Email" /> | ||
|
||
<!-- Email Message Input --> | ||
<label style="margin-top: 10px;">Email Message:</label> | ||
<textarea ng-model="emailMessage" rows="5" style="width: 100%;" placeholder="Type your message here..."></textarea> | ||
|
||
<!-- Buttons Row --> | ||
<div style="margin-top: 10px;"> | ||
<input type="file" ng-model="attachment" style="margin-right: 10px;" /> | ||
<button ng-click="sendEmail()">📧 Send Email</button> | ||
</div> | ||
</div> | ||
|
||
<!-- Minimal Padding for Table --> | ||
<style> | ||
.padded-table th, .padded-table td { | ||
padding: 5px; | ||
} | ||
</style> | ||
|