This is the javascript file:
import nodemailer from 'nodemailer';
function SendEmail() {
let message = {
from: '"foo@example.com" <foo@example.com>',
to: "example@example.com",
subject: "Hello",
text:"Hello world",
};
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false,
requireTLS: true,
auth: {
user: 'email',
pass: 'password'
},
logger: true
});
transporter.sendMail(message);
}
This is ho the HTML looks like:
<!DOCTYPE html>
<html>
<head>
<script type="module" src="sendEmail.js"></script>
</head>
<body>
<input onclick="SendEmail()" value="Submit">
</body>
</html>
When I open the HTML document I get the error: Error resolving module specifier “nodemailer”. Relative module specifiers must start with “./”, “../” or “/”.
And when I click on the input I get the error: Uncaught ReferenceError: SendEmail is not defined
But when I instantly call the SendEmail function and run the script using the command : node sendEmail.js it works. What's the problem?