Skip to content

Commit

Permalink
Merge pull request #403 from sreevidya-16/sreevidya1
Browse files Browse the repository at this point in the history
Sendgrid API
  • Loading branch information
dinxsh authored Aug 9, 2024
2 parents ebb22b2 + 06fd017 commit e7cc925
Show file tree
Hide file tree
Showing 6 changed files with 1,347 additions and 0 deletions.
26 changes: 26 additions & 0 deletions New_APIs/SendGrid API/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>SendGrid Email Sender</title>
</head>
<body>
<header>
<h1>SendGrid Email Sender</h1>
</header>
<main>
<section>
<form id="email-form">
<input type="email" id="to" placeholder="Recipient Email" required>
<input type="text" id="subject" placeholder="Subject" required>
<textarea id="message" placeholder="Message" required></textarea>
<button type="submit">Send Email</button>
</form>
<div id="status"></div>
</section>
</main>
<script src="index.js"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions New_APIs/SendGrid API/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
document.getElementById('email-form').addEventListener('submit', async (e) => {
e.preventDefault();

const to = document.getElementById('to').value;
const subject = document.getElementById('subject').value;
const message = document.getElementById('message').value;

try {
const response = await fetch('/send-email', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ to, subject, message })
});

const data = await response.json();

if (data.success) {
document.getElementById('status').textContent = 'Email sent successfully!';
} else {
document.getElementById('status').textContent = 'Failed to send email.';
}
} catch (error) {
console.error('Error:', error);
document.getElementById('status').textContent = 'An error occurred while sending the email.';
}
});
Loading

0 comments on commit e7cc925

Please sign in to comment.