-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.js
155 lines (133 loc) · 5.54 KB
/
mail.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// © Copyright 2023 Zymono. All Rights Reserved. No Copying/Modifying/Stealing Allowed!
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.14.0/firebase-app.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
import { getStorage, ref, uploadString, getDownloadURL } from "https://email-1.zymono.repl.co/1.0/storageapi.js";
export function saveCloud(where, what) {
// For Firebase JS SDK v7.20.0 and later, measurenodementId is optional
const firebaseConfig = {
apiKey: "AIzaSyBzBFr-dt2pxVWr3FePWxfAIM16wHfFVuY",
authDomain: "zymono-codemail.firebaseapp.com",
projectId: "zymono-codemail",
storageBucket: "zymono-codemail.appspot.com",
messagingSenderId: "602783646028",
appId: "1:602783646028:web:0eb4e7ff60d2510ed58fe9"
};
// export default firebaseConfig;
// Initialize Firebase
const app = initializeApp(firebaseConfig);
var sr = "userMail/" + where
const storage = getStorage();
const storageRef = ref(storage, sr);
uploadString(storageRef, what).then((snapshot) => {
console.log('Subscribed List: ' + what);
})
}
export async function subscribe(mailingID, formName, redirectURL) {
fetch('https://api.ipify.org/?format=json')
.then(response => response.json())
.then(data => {
const firebaseConfig = {
apiKey: "AIzaSyBzBFr-dt2pxVWr3FePWxfAIM16wHfFVuY",
authDomain: "zymono-codemail.firebaseapp.com",
projectId: "zymono-codemail",
storageBucket: "zymono-codemail.appspot.com",
messagingSenderId: "602783646028",
appId: "1:602783646028:web:0eb4e7ff60d2510ed58fe9"
};
// export default firebaseConfig;
// Initialize Firebase
const app = initializeApp(firebaseConfig);
var get = 'userMail/recentIP.zyc'
getDownloadURL(ref(getStorage(), get))
.then((url) => {
// // `url` is the download URL for your variable
try {
const xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onload = function() {
if (xhr.status === 200) {
if(xhr.responseText == data.ip) {
alert('Error Cannot Submit More Than One Email Address!')
history.back()
} else {
const email = document.getElementById('codemail-email').value
saveCloud(mailingID + '/' + email + '/type.zyc', formName)
saveCloud(mailingID + '/' + email + '/ip.zyc', data.ip)
saveCloud('recentIP.zyc', data.ip)
const emailServiceId = 'service_5lifede';
const emailTemplateId = 'template_7izd1am';
emailjs.init('ySPV8Qf0psFEUPlLL');
const html = `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Zymono Codemail - Signup Confirmation</title>
<style>
body {
font-family: Arial, sans-serif;
font-size: 16px;
line-height: 1.6;
color: #444;
background-color: #f9f9f9;
}
h1 {
font-size: 24px;
font-weight: bold;
color: #555;
margin-bottom: 20px;
}
p {
margin-bottom: 20px;
}
a {
color: #3498db;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>Thank you for joining a Zymono Codemail community!</h1>
<p>We're thrilled to have you as part of their community. You'll be receiving updates soon!</p>
<p>If you didn't intend to join any Zymono Codemail community, please let us know by clicking <a href="https://codemail.zymono.com/notme/?id=${mailingID}&email=${email}">here</a>.</p>
<p>Thanks,<br>The Zymono Codemail Team</p>
</body>
</html>
`
// Define the email parameters
const emailParams = {
to_email: document.getElementById('codemail-email').value,
from_name: 'Zymono',
reply_to: 'inovate@code.mail.zymono.com',
html: html
};
// Send the email using the EmailJS API
emailjs.send(emailServiceId, emailTemplateId, emailParams)
.then(() => {
console.log('Verification email sent successfully.');
window.location.href = redirectURL
})
.catch((error) => {
console.error(error);
});
}
} else {
console.error(xhr.statusText);
const err3 = error
}
};
xhr.onerror = function(error) {
console.error(error);
const err3 = error
};
xhr.send();
} catch (error) {
}
}) //end
return data.ip
})
}