Skip to content

Commit

Permalink
Fixed my async functions and will now display all emails that failed
Browse files Browse the repository at this point in the history
  • Loading branch information
HohShenYien committed Dec 25, 2021
1 parent d177645 commit d8e8a6f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion design.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"counters":{"u_column":2,"u_row":2,"u_content_heading":1,"u_content_image":1,"u_content_text":1},"body":{"rows":[{"cells":[1],"columns":[{"contents":[{"type":"heading","values":{"containerPadding":"10px","headingType":"h1","fontFamily":{"label":"Arial","value":"arial,helvetica,sans-serif"},"fontSize":"22px","textAlign":"left","lineHeight":"140%","linkStyle":{"inherit":true,"linkColor":"#0000ee","linkHoverColor":"#0000ee","linkUnderline":true,"linkHoverUnderline":true},"hideDesktop":false,"_meta":{"htmlID":"u_content_heading_1","htmlClassNames":"u_content_heading"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true,"text":"<strong>Forehead slapping time </strong>🤚"}}],"values":{"backgroundColor":"","padding":"0px","border":{},"_meta":{"htmlID":"u_column_1","htmlClassNames":"u_column"}}}],"values":{"displayCondition":null,"columns":false,"backgroundColor":"","columnsBackgroundColor":"","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"padding":"0px","hideDesktop":false,"_meta":{"htmlID":"u_row_1","htmlClassNames":"u_row"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true}},{"cells":[1],"columns":[{"contents":[{"type":"text","values":{"containerPadding":"10px","textAlign":"left","lineHeight":"140%","linkStyle":{"inherit":true,"linkColor":"#0000ee","linkHoverColor":"#0000ee","linkUnderline":true,"linkHoverUnderline":true},"_meta":{"htmlID":"u_content_text_1","htmlClassNames":"u_content_text"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true,"text":"<p style=\"font-size: 14px; line-height: 140%;\"><span style=\"font-size: 14px; line-height: 19.6px; color: #e03e2d;\">Your forehead gonna be slapped soon! ^*name*^</span></p>"}},{"type":"image","values":{"containerPadding":"10px","src":{"url":"https://unroll-images-production.s3.amazonaws.com/projects/0/1633946756049-46250.jpg","width":1920,"height":1200},"textAlign":"center","altText":"","action":{"name":"web","values":{"href":"","target":"_blank"}},"hideDesktop":false,"_meta":{"htmlID":"u_content_image_1","htmlClassNames":"u_content_image"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true}}],"values":{"backgroundColor":"","padding":"0px","border":{},"borderRadius":"0px","_meta":{"htmlID":"u_column_2","htmlClassNames":"u_column"}}}],"values":{"displayCondition":null,"columns":false,"backgroundColor":"","columnsBackgroundColor":"","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"padding":"0px","hideDesktop":false,"_meta":{"htmlID":"u_row_2","htmlClassNames":"u_row"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true}}],"values":{"textColor":"#000000","backgroundColor":"#e7e7e7","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"contentWidth":"900px","contentAlign":"center","fontFamily":{"label":"Arial","value":"arial,helvetica,sans-serif"},"preheaderText":"","linkStyle":{"body":true,"linkColor":"#0000ee","linkHoverColor":"#0000ee","linkUnderline":true,"linkHoverUnderline":true},"_meta":{"htmlID":"u_body","htmlClassNames":"u_body"}}},"schemaVersion":6}
{"counters":{"u_column":3,"u_row":3,"u_content_heading":1,"u_content_image":1,"u_content_text":1},"body":{"rows":[{"cells":[1],"columns":[{"contents":[{"type":"heading","values":{"containerPadding":"10px","headingType":"h1","fontFamily":{"label":"Arial","value":"arial,helvetica,sans-serif"},"fontSize":"22px","textAlign":"left","lineHeight":"140%","linkStyle":{"inherit":true,"linkColor":"#0000ee","linkHoverColor":"#0000ee","linkUnderline":true,"linkHoverUnderline":true},"hideDesktop":false,"_meta":{"htmlID":"u_content_heading_1","htmlClassNames":"u_content_heading"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true,"text":"<strong>Hello brainy girl</strong>"}}],"values":{"backgroundColor":"","padding":"0px","border":{},"_meta":{"htmlID":"u_column_1","htmlClassNames":"u_column"}}}],"values":{"displayCondition":null,"columns":false,"backgroundColor":"","columnsBackgroundColor":"","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"padding":"0px","hideDesktop":false,"_meta":{"htmlID":"u_row_1","htmlClassNames":"u_row"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true}},{"cells":[1],"columns":[{"contents":[{"type":"text","values":{"containerPadding":"10px","textAlign":"left","lineHeight":"140%","linkStyle":{"inherit":true,"linkColor":"#0000ee","linkHoverColor":"#0000ee","linkUnderline":true,"linkHoverUnderline":true},"hideDesktop":false,"_meta":{"htmlID":"u_content_text_1","htmlClassNames":"u_content_text"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true,"text":"<p style=\"font-size: 14px; line-height: 140%;\">Hi :D</p>"}}],"values":{"backgroundColor":"","padding":"0px","border":{},"_meta":{"htmlID":"u_column_2","htmlClassNames":"u_column"}}}],"values":{"displayCondition":null,"columns":false,"backgroundColor":"","columnsBackgroundColor":"","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"padding":"0px","hideDesktop":false,"_meta":{"htmlID":"u_row_2","htmlClassNames":"u_row"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true}}],"values":{"textColor":"#000000","backgroundColor":"#e7e7e7","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"contentWidth":"900px","contentAlign":"center","fontFamily":{"label":"Arial","value":"arial,helvetica,sans-serif"},"preheaderText":"","linkStyle":{"body":true,"linkColor":"#0000ee","linkHoverColor":"#0000ee","linkUnderline":true,"linkHoverUnderline":true},"_meta":{"htmlID":"u_body","htmlClassNames":"u_body"}}},"schemaVersion":6}
1 change: 1 addition & 0 deletions mydesign.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"counters":{"u_column":3,"u_row":3,"u_content_heading":1,"u_content_image":1,"u_content_text":1},"body":{"rows":[{"cells":[1],"columns":[{"contents":[{"type":"heading","values":{"containerPadding":"10px","headingType":"h1","fontFamily":{"label":"Arial","value":"arial,helvetica,sans-serif"},"fontSize":"22px","textAlign":"left","lineHeight":"140%","linkStyle":{"inherit":true,"linkColor":"#0000ee","linkHoverColor":"#0000ee","linkUnderline":true,"linkHoverUnderline":true},"hideDesktop":false,"_meta":{"htmlID":"u_content_heading_1","htmlClassNames":"u_content_heading"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true,"text":"<strong>Hello world</strong>"}}],"values":{"backgroundColor":"","padding":"0px","border":{},"_meta":{"htmlID":"u_column_1","htmlClassNames":"u_column"}}}],"values":{"displayCondition":null,"columns":false,"backgroundColor":"","columnsBackgroundColor":"","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"padding":"0px","hideDesktop":false,"_meta":{"htmlID":"u_row_1","htmlClassNames":"u_row"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true}},{"cells":[1],"columns":[{"contents":[{"type":"image","values":{"containerPadding":"10px","src":{"url":"https://s3.amazonaws.com/unroll-images-production/projects%2F0%2F1634221866389-thailand_malaysia_registering_marriage_bangkok_thailand_mrdefinite.net_kenneth_kusala.webp","width":672,"height":372},"textAlign":"center","altText":"","action":{"name":"web","values":{"href":"","target":"_blank"}},"hideDesktop":false,"_meta":{"htmlID":"u_content_image_1","htmlClassNames":"u_content_image"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true}}],"values":{"backgroundColor":"","padding":"0px","border":{},"_meta":{"htmlID":"u_column_3","htmlClassNames":"u_column"}}}],"values":{"displayCondition":null,"columns":false,"backgroundColor":"","columnsBackgroundColor":"","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"padding":"0px","hideDesktop":false,"_meta":{"htmlID":"u_row_3","htmlClassNames":"u_row"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true}},{"cells":[1],"columns":[{"contents":[{"type":"text","values":{"containerPadding":"10px","textAlign":"left","lineHeight":"140%","linkStyle":{"inherit":true,"linkColor":"#0000ee","linkHoverColor":"#0000ee","linkUnderline":true,"linkHoverUnderline":true},"_meta":{"htmlID":"u_content_text_1","htmlClassNames":"u_content_text"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true,"text":"<p style=\"font-size: 14px; line-height: 140%;\">Hi ^*name*^</p>"}}],"values":{"backgroundColor":"","padding":"0px","border":{},"_meta":{"htmlID":"u_column_2","htmlClassNames":"u_column"}}}],"values":{"displayCondition":null,"columns":false,"backgroundColor":"","columnsBackgroundColor":"","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"padding":"0px","hideDesktop":false,"_meta":{"htmlID":"u_row_2","htmlClassNames":"u_row"},"selectable":true,"draggable":true,"duplicatable":true,"deletable":true,"hideable":true}}],"values":{"textColor":"#000000","backgroundColor":"#e7e7e7","backgroundImage":{"url":"","fullWidth":true,"repeat":false,"center":true,"cover":false},"contentWidth":"900px","contentAlign":"center","fontFamily":{"label":"Arial","value":"arial,helvetica,sans-serif"},"preheaderText":"","linkStyle":{"body":true,"linkColor":"#0000ee","linkHoverColor":"#0000ee","linkUnderline":true,"linkHoverUnderline":true},"_meta":{"htmlID":"u_body","htmlClassNames":"u_body"}}},"schemaVersion":6}
15 changes: 9 additions & 6 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<div style="width: 100%; height: 100%; display: flex; flex-direction: column;
justify-content: center; align-items: center;">
<v-progress-circular
:value="progress * 100"
:value="cur * 100"
>
</v-progress-circular>
{{progress * 100}}%
{{progress}}
</div>
</v-overlay>
<v-app-bar app color="primary" dark>
Expand Down Expand Up @@ -67,7 +67,8 @@ export default {
html: '',
sending: false,
progress: 0,
cert: null
cert: null,
cur: 0
}),
methods: {
goHome() {
Expand Down Expand Up @@ -95,16 +96,18 @@ export default {
console.log(design);
this.html = design;
},
changeProgress(p) {
changeProgress(n, t) {
this.sending = true;
this.progress = p;
this.progress = n + " / " + t;
this.cur = n / t;
},
completed(e) {
console.log("Completed2");
this.sending = false;
this.progress = 0;
this.cur = 0;
if (!e) {
alert("Failed to send some emails, please refer error log to see what is missing");
alert("Failed to send some emails, please check the new data on table for details");
}
}
},
Expand Down
25 changes: 11 additions & 14 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ if (isDevelopment) {
// events from renderers
ipcMain.on('send-email', async (event, arg) => {
await sendIt(arg).then(res=> {
event.reply("email-reply", "success");
}).catch((res,err) => {
event.reply("email-reply", "success");
}).catch(err => {
console.log(err);
event.reply("email-reply", "fails");
})
})
Expand All @@ -97,24 +98,20 @@ async function sendIt(val) {
pass: val.password,
},
});

const mailOptions = {
from: val.email,
to: val.to,
subject: val.subject,
html: val.html,
attachments: val.attachments
};

transporter.sendMail(mailOptions, function (err, info) {
if (err) {
return new Promise(function(resolve, reject) {
reject();
});
} else {
return new Promise(resolve => {
return new Promise(function(resolve, reject) {
transporter.sendMail(mailOptions, function (err, info) {
if (err) {
reject(err);
} else {
resolve();
});
}
});
}
});
})
}
16 changes: 10 additions & 6 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export default {
},
methods: {
async sendEmail() {
let obj = await this.emailObj();
let obj = this.emailObj();
ipcRenderer.send('send-email', obj);
},
send() {
Expand Down Expand Up @@ -225,14 +225,18 @@ export default {
},
emailListener(evt, message) {
if (message == 'fails') {
console.log("FAILED");
console.log(this.selected[this.currentId]);
this.failed.push(this.selected[this.currentId]);
}
if (++this.currentId < this.selected.length) {
this.$emit('progress', this.currentId / this.selected.length);
this.sendEmail();
this.$emit('progress', this.currentId, this.selected.length);
setTimeout(() => this.sendEmail(), 500);
} else {
this.$emit("completed", this.failed.length == 0);
this.currentId = 0;
console.log(this.failed);
this.$emit("completed", this.failed.length === 0);
this.selected = [];
this.recipients = this.failed;
}
},
goTo(link) {
Expand Down Expand Up @@ -285,7 +289,7 @@ export default {
}
}
},
async emailObj() {
emailObj() {
let formatHtml = this.html;
for (let header of this.headers) {
formatHtml = formatHtml.replace('^*' + header.value + '*^', this.selected[this.currentId][header.value]);
Expand Down

0 comments on commit d8e8a6f

Please sign in to comment.