-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
55d32a0
commit f95969e
Showing
6 changed files
with
79 additions
and
30 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 |
---|---|---|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge | |
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.buyProduct = void 0; | ||
exports.soldMail = void 0; | ||
const nodemailer = require("nodemailer"); | ||
const transporter = nodemailer.createTransport({ | ||
host: "smtp.gmail.com", | ||
|
@@ -20,19 +20,36 @@ const transporter = nodemailer.createTransport({ | |
pass: "qoii dhsi hkzq yxte", | ||
}, | ||
}); | ||
// async..await is not allowed in global scope, must use a wrapper | ||
function buyProduct(userMail) { | ||
function soldMail(userMail, sellerMail, sellPrice, productName) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// send mail with defined transport object | ||
// Define the recipients | ||
const recipients = sellerMail ? `${userMail}, ${sellerMail}` : userMail; | ||
// Define the HTML content for the receipt | ||
const htmlContent = ` | ||
<div> | ||
<h1>Bid Receipt</h1> | ||
<p>Item was sold!!</p> | ||
<p><strong>Product Name:</strong> ${productName}</p> | ||
<p><strong>Sell Price:</strong> INR${sellPrice.toFixed(2)}</p> | ||
<p><strong>Buyer Mail:</strong> INR${userMail}</p> | ||
<p><strong>Seller Mail:</strong> INR${sellerMail}</p> | ||
<hr> | ||
<p> | ||
This is to inform you that biding ${productName} has been completed at a price of INR ${sellPrice.toFixed(2)}. to the user ${userMail} | ||
</p> | ||
<p>This is a confirmation of the sale transaction. Please keep it for your records.</p> | ||
</div> | ||
`; | ||
// Send mail with defined transport object | ||
const info = yield transporter.sendMail({ | ||
from: '"BidHub" <[email protected]>', | ||
to: `${userMail}`, | ||
subject: "Hello ✔", | ||
text: "Hello world?", | ||
html: "<b>Hello world?</b>", // html body | ||
to: recipients, | ||
subject: "Product Sold ✔", | ||
text: `Biding ${productName} has been completed at a price of INR ${sellPrice.toFixed(2)}. to the user ${userMail} `, | ||
html: htmlContent, // html body | ||
}); | ||
console.log("Message sent: %s", info.messageId); | ||
// Message sent: <[email protected]> | ||
}); | ||
} | ||
exports.buyProduct = buyProduct; | ||
exports.soldMail = soldMail; |
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
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 |
---|---|---|
|
@@ -11,17 +11,42 @@ const transporter = nodemailer.createTransport({ | |
|
||
}); | ||
|
||
// async..await is not allowed in global scope, must use a wrapper | ||
export async function buyProduct(userMail:string | string[]) { | ||
// send mail with defined transport object | ||
export async function soldMail( | ||
userMail: string, | ||
sellerMail: string | undefined, | ||
sellPrice: number, | ||
productName: string | ||
): Promise<void> { | ||
// Define the recipients | ||
const recipients = sellerMail ? `${userMail}, ${sellerMail}` : userMail; | ||
|
||
// Define the HTML content for the receipt | ||
const htmlContent = ` | ||
<div> | ||
<h1>Bid Receipt</h1> | ||
<p>Item was sold!!</p> | ||
<p><strong>Product Name:</strong> ${productName}</p> | ||
<p><strong>Sell Price:</strong> INR${sellPrice.toFixed(2)}</p> | ||
<p><strong>Buyer Mail:</strong> ${userMail}</p> | ||
<p><strong>Seller Mail:</strong> ${sellerMail}</p> | ||
<hr> | ||
<p> | ||
This is to inform you that biding ${productName} has been completed at a price of INR ${sellPrice.toFixed(2)}. to the user ${userMail} | ||
</p> | ||
<p>This is a confirmation of the sale transaction. Please keep it for your records.</p> | ||
</div> | ||
`; | ||
|
||
// Send mail with defined transport object | ||
const info = await transporter.sendMail({ | ||
from: '"BidHub" <[email protected]>', // sender address | ||
to: `${userMail}`, // list of receivers | ||
subject: "Hello ✔", // Subject line | ||
text: "Hello world?", // plain text body | ||
html: "<b>Hello world?</b>", // html body | ||
to: recipients, // list of receivers | ||
subject: "Product Sold ✔", // Subject line | ||
text: `Biding ${productName} has been completed at a price of INR ${sellPrice.toFixed(2)}. to the user ${userMail} `, // plain text body | ||
html: htmlContent, // html body | ||
}); | ||
|
||
|
||
console.log("Message sent: %s", info.messageId); | ||
// Message sent: <[email protected]> | ||
} | ||
|
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