Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Albin Geraud Kouatcho Nkuigwa
PSE_Projekt
Commits
9f175b4c
Commit
9f175b4c
authored
Jun 25, 2018
by
Janik Münzenberger
Browse files
Send job image as attachment with email
parent
26f5816a
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/app/components/email/email.component.html
View file @
9f175b4c
...
...
@@ -40,10 +40,10 @@
<textarea
type=
"email"
rows=
"5"
class=
"form-control"
formControlName=
"email_message"
id=
"email_message"
required
></textarea>
</div>
</div>
<div
class=
"form-group row"
*ngIf=
"
message
"
>
<div
class=
"form-group row"
*ngIf=
"
content?.result
"
>
<label
for=
"email_attachment"
class=
"col-sm-2 col-form-label"
>
{{"EMAIL.ATTACHMENT" | translate}}:
</label>
<div
class=
"col-sm-10"
>
<pre
type=
"email"
rows=
"6"
id=
"email_attachment"
class=
"form-control default-message"
readonly
disabled
>
{{
message
}}
</pre>
<pre
type=
"email"
rows=
"6"
id=
"email_attachment"
class=
"form-control default-message"
readonly
disabled
>
{{
content?.result | stringify
}}
</pre>
</div>
</div>
</form>
...
...
src/app/components/email/email.component.ts
View file @
9f175b4c
...
...
@@ -13,7 +13,7 @@ import { UserService } from '../../services/user.service';
export
class
EmailComponent
implements
OnInit
{
@
Input
()
receivers
:
{
email
:
string
,
name
:
string
}[];
@
Input
()
message
:
string
=
""
;
@
Input
()
content
:
any
;
emailForm
:
FormGroup
;
sent
:
boolean
=
false
;
...
...
@@ -42,12 +42,13 @@ export class EmailComponent implements OnInit {
sender
:
this
.
emailForm
.
get
(
'
email_sender
'
).
value
,
receiver
:
this
.
emailForm
.
get
(
'
email_receiver
'
).
value
,
subject
:
"
Krankheitsanalyse von
"
+
this
.
emailForm
.
get
(
'
email_sender
'
).
value
,
message
:
this
.
emailForm
.
get
(
'
email_message
'
).
value
+
"
\n\n
"
+
this
.
message
message
:
this
.
emailForm
.
get
(
'
email_message
'
).
value
+
"
\n\n
"
,
content
:
this
.
content
};
this
.
emailService
.
sendEmail
(
email
)
.
then
(
x
=>
this
.
sent
=
true
)
.
catch
(
err
=>
{
console
.
log
(
err
);
console
.
error
(
err
);
this
.
error
=
true
;
});
}
...
...
src/app/model/IEmail.ts
View file @
9f175b4c
...
...
@@ -2,5 +2,6 @@ export interface IEmail {
sender
:
string
,
receiver
:
string
,
subject
?:
string
,
message
:
string
message
:
string
,
content
?:
any
;
}
\ No newline at end of file
src/app/pages/result/result.component.html
View file @
9f175b4c
...
...
@@ -23,4 +23,4 @@
</div>
</div>
<app-email
[receivers]=
"gardeners"
[message]=
"job?.result | stringify"
#email
></app-email>
\ No newline at end of file
<app-email
[receivers]=
"gardeners"
[content]=
"job"
#email
></app-email>
\ No newline at end of file
src/backend/controller/email.js
View file @
9f175b4c
const
nodemailer
=
require
(
'
nodemailer
'
);
const
winston
=
require
(
'
winston
'
);
const
errors
=
require
(
'
../lib/errors
'
);
const
path
=
require
(
'
path
'
);
const
fs
=
require
(
'
fs
'
);
var
transport
;
createTransport
();
...
...
@@ -42,7 +44,7 @@ function email(req, res) {
let
receiver
=
req
.
body
.
receiver
;
let
subject
=
req
.
body
.
subject
;
let
msg
=
req
.
body
.
message
;
let
content
=
req
.
body
.
content
;
// create a setup message option
let
mailOptions
=
{
...
...
@@ -52,6 +54,24 @@ function email(req, res) {
text
:
msg
};
if
(
content
){
if
(
content
.
result
){
mailOptions
.
text
+=
`This email was requested by
${
sender
}
\n\n`
;
mailOptions
.
text
+=
`Analysis results for
${
content
.
plant
.
name
}
from https://psehda.herokuapp.com/:\n`
;
for
(
let
r
of
content
.
result
)
{
mailOptions
.
text
+=
`
${
r
.
disease_id
?
r
.
disease_id
.
name
:
'
No disease
'
}
=>
${
r
.
confidence
}
\n`
;
}
}
if
(
content
.
image_url
){
const
image_path
=
path
.
join
(
__dirname
,
'
../assets/analysis
'
,
path
.
basename
(
content
.
image_url
));
if
(
fs
.
existsSync
(
image_path
)){
mailOptions
.
attachments
=
[{
filename
:
'
diseased_plant.jpg
'
,
path
:
image_path
}];
}
}
}
// send the E-mail with sendMail using the defined transporter
transport
.
sendMail
(
mailOptions
)
...
...
@@ -68,4 +88,4 @@ function email(req, res) {
module
.
exports
=
{
email
}
\ No newline at end of file
};
\ No newline at end of file
src/backend/controller/notification.js
View file @
9f175b4c
...
...
@@ -30,7 +30,7 @@ function sendPushNotification(job){
const
notificationPayload
=
{
notification
:
{
title
:
"
You`re result is there!
"
,
body
:
`We received the results for your analysed plant!
Follow
${
url
}
`
,
body
:
`We received the results for your analysed plant!
You con find the result at
${
config
.
base_url
+
url
}
`
,
icon
:
'
/uploads/icon.png
'
,
vibrate
:
[
100
,
50
,
100
],
data
:
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment