-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
72 lines (57 loc) · 2.31 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require(["./lib/firemail/lib/firemail"], function(firemail) {
window.sendMail = function(){
// Disable "Send mail" button
document.getElementById("sendBtn").disabled = true;
// Setup e-mail object
var mail = {
from: document.getElementById("from").value,
to: document.getElementById("to").value,
subject: document.getElementById("subject").value,
text: document.getElementById("text").value,
headers:{
"x-mailer": "firemail"
},
smtp: {
host: document.getElementById("host").value,
port: Number(document.getElementById("port").value),
useSSL: !!document.getElementById("ssl").checked,
auth: document.getElementById("user").value ? {
user: document.getElementById("user").value,
pass: document.getElementById("pass").value
} : false
}
};
// Store mail data
localStorage.firemailDemo = JSON.stringify(mail);
// Callback function to run once the message has been sent
var callback = function(err, success){
if(err){
alert(err.message || err);
}else{
alert(success ? "Mail sent" : "Failed sending mail");
}
document.getElementById("sendBtn").disabled = false;
};
// If attachment has been specified load the contents before sending
if(document.getElementById("attachment").files.length){
var reader = new FileReader(),
file = document.getElementById("attachment").files[0];
// run once the file has been loaded
reader.onload = function(evt){
// add an attachment object to the attachment list
mail.attachments = [{
content: new Uint8Array(evt.target.result),
fileName: file.fileName,
contentType: file.type
}];
// Send mail
firemail(mail, callback);
};
// start loading file
reader.readAsArrayBuffer(file);
}else{
// Send mail
firemail(mail, callback);
}
};
});