dropkickJesus999 commited on
Commit
3ff66c4
·
verified ·
1 Parent(s): 29f0a95

Error: about:srcdoc Failed to send email: sendEmIl is not defined. Please define it however necessary to actually send emails from this app. I need functionality before looks or anything else. It needs to be 100%in working order or it fails.

Browse files
components/create-account.js CHANGED
@@ -83,15 +83,16 @@ class CustomCreateAccount extends HTMLElement {
83
  composed: true
84
  }));
85
  // Create welcome email
86
- await sendEmail(user.uid, {
87
  to: email,
88
  from: "welcome@edughost.com",
89
  subject: "Welcome to eduGHoSt!",
90
  body: `Welcome to your new eduGHoSt email account!\n\nYour temporary email address is: ${email}\n\nThis email will expire in 24 hours.`,
91
  preview: "Welcome to your new eduGHoSt email account!",
92
- date: new Date().toLocaleString()
 
93
  });
94
- } catch (error) {
95
  alert(`Account creation failed: ${error.message}`);
96
  console.error("Account creation error:", error);
97
  }
 
83
  composed: true
84
  }));
85
  // Create welcome email
86
+ await window.sendEmail(userCredential.user.uid, {
87
  to: email,
88
  from: "welcome@edughost.com",
89
  subject: "Welcome to eduGHoSt!",
90
  body: `Welcome to your new eduGHoSt email account!\n\nYour temporary email address is: ${email}\n\nThis email will expire in 24 hours.`,
91
  preview: "Welcome to your new eduGHoSt email account!",
92
+ date: new Date().toLocaleString(),
93
+ timestamp: firebase.firestore.FieldValue.serverTimestamp()
94
  });
95
+ } catch (error) {
96
  alert(`Account creation failed: ${error.message}`);
97
  console.error("Account creation error:", error);
98
  }
components/email-composer.js CHANGED
@@ -64,14 +64,16 @@ class CustomEmailComposer extends HTMLElement {
64
  }
65
 
66
  try {
67
- await sendEmail(userId, {
68
  to,
69
  subject,
70
  body,
71
  from: auth.currentUser.email + " (via eduGHoSt)",
72
- timestamp: new Date()
 
 
73
  });
74
- alert('Email sent successfully!');
75
  this.clearForm();
76
  } catch (error) {
77
  alert(`Failed to send email: ${error.message}`);
 
64
  }
65
 
66
  try {
67
+ const emailId = await window.sendEmail(userId, {
68
  to,
69
  subject,
70
  body,
71
  from: auth.currentUser.email + " (via eduGHoSt)",
72
+ preview: body.substring(0, 100) + (body.length > 100 ? "..." : ""),
73
+ date: new Date().toLocaleString(),
74
+ timestamp: firebase.firestore.FieldValue.serverTimestamp()
75
  });
76
+ alert('Email sent successfully!');
77
  this.clearForm();
78
  } catch (error) {
79
  alert(`Failed to send email: ${error.message}`);
script.js CHANGED
@@ -37,21 +37,23 @@ async function createUserAccount(email, password) {
37
  throw error;
38
  }
39
  }
40
-
41
- // Function to send email
42
- async function sendEmail(userId, emailData) {
43
  try {
44
- await db.collection('emails').add({
45
  ...emailData,
46
  userId: userId,
47
  read: false,
48
  createdAt: firebase.firestore.FieldValue.serverTimestamp()
49
  });
 
 
 
50
  } catch (error) {
 
51
  throw error;
52
  }
53
  }
54
-
55
  // Function to fetch emails
56
  async function fetchEmails(userId) {
57
  try {
 
37
  throw error;
38
  }
39
  }
40
+ // Global email sending function
41
+ window.sendEmail = async function(userId, emailData) {
 
42
  try {
43
+ const emailRef = await db.collection('emails').add({
44
  ...emailData,
45
  userId: userId,
46
  read: false,
47
  createdAt: firebase.firestore.FieldValue.serverTimestamp()
48
  });
49
+
50
+ // Return the email ID for reference
51
+ return emailRef.id;
52
  } catch (error) {
53
+ console.error("Error sending email:", error);
54
  throw error;
55
  }
56
  }
 
57
  // Function to fetch emails
58
  async function fetchEmails(userId) {
59
  try {