-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail-service.js
More file actions
94 lines (75 loc) · 2.57 KB
/
Copy pathemail-service.js
File metadata and controls
94 lines (75 loc) · 2.57 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Direct email sending using a simple approach
(function() {
// Function to send email directly to romrotem15@gmail.com
function sendEmail(subject, body) {
// Create a link to open the default mail client
const mailtoLink = `mailto:romrotem15@gmail.com?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}`;
// Create a hidden link element
const link = document.createElement('a');
link.href = mailtoLink;
link.style.display = 'none';
document.body.appendChild(link);
// Click the link to open the mail client
link.click();
// Remove the link element
setTimeout(() => {
document.body.removeChild(link);
}, 100);
// Show a notification to the user
alert('נפתח חלון דואר אלקטרוני לשליחת התראה. אנא השלם את השליחה.');
return Promise.resolve(true);
}
// Send notification for new user registration
function sendUserRegistrationEmail(user) {
const subject = 'New User Registration - Cakes Website';
const body = `
New User Registration Details:
Name: ${user.fullName}
Email: ${user.email}
Phone: ${user.phone}
Registration Date: ${new Date().toLocaleString()}
`;
return sendEmail(subject, body);
}
// Send notification for new order
function sendOrderNotificationEmail(order, user) {
// Format order items for email
const itemsList = order.items.map(item =>
`${item.name} - ${item.quantity} × ${item.price} שקל = ${item.quantity * item.price} שקל`
).join('\n');
const subject = `New Order #${order.id} - Cakes Website`;
const body = `
New Order Details:
Order ID: ${order.id}
Order Date: ${new Date(order.orderDate).toLocaleString()}
Customer Information:
Name: ${user.name}
Email: ${user.email}
Phone: ${user.phone}
Delivery Information:
Delivery Date: ${new Date(order.deliveryDate).toLocaleString()}
Delivery Address: ${order.deliveryAddress}
Order Items:
${itemsList}
Total: ${order.total} שקל
Special Notes:
${order.notes || 'No special notes'}
`;
return sendEmail(subject, body);
}
// Save order details to local storage for reference
function saveNotification(type, data) {
const notifications = JSON.parse(localStorage.getItem('notifications') || '[]');
notifications.push({
type,
data,
timestamp: new Date().toISOString()
});
localStorage.setItem('notifications', JSON.stringify(notifications));
}
// Expose functions globally
window.emailService = {
sendUserRegistrationEmail,
sendOrderNotificationEmail
};
})();