Last active
December 8, 2021 07:16
-
-
Save kuc-arc-f/4e7c72d1f298ce93a320a924d9165edd to your computer and use it in GitHub Desktop.
remix, mail sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* mail test */ | |
import { useEffect, useRef, useState } from "react"; | |
import type { MetaFunction, LoaderFunction } from "remix"; | |
import { useLoaderData, Link } from "remix"; | |
import { Form, json, useActionData, redirect } from "remix"; | |
import Config from '../../../config' | |
import mailer from '../../lib/mailer' | |
export let meta: MetaFunction = () => { | |
return { | |
title: "test, mail", | |
description: "Welcome to remix!" | |
}; | |
}; | |
export async function action({ request }) { | |
let formData = await request.formData(); | |
let to_mail = formData.get("to_mail"); | |
console.log(to_mail); | |
//console.log(Config); | |
const receiverEmailAddress = to_mail; | |
console.log(Config.SMTP_HOST); | |
console.log(Config.SMTP_PORT); | |
console.log(Config.SMTP_AUTH_USER); | |
console.log(Config.SMTP_AUTH_PASS); | |
console.log(Config.SEND_MAIL_ADDRESS); | |
let transporter = mailer.createTransport({ | |
host: Config.SMTP_HOST, | |
port: Config.SMTP_PORT, | |
secure: Config.SMTP_SECURE, | |
auth: { | |
user: Config.SMTP_AUTH_USER, | |
pass: Config.SMTP_AUTH_PASS, | |
}, | |
}); | |
let info = await transporter.sendMail({ | |
from: Config.SEND_MAIL_ADDRESS, | |
to: receiverEmailAddress, | |
subject: "title_1", | |
text: "text_sample", | |
}); | |
console.log("Message sent: %s", info.messageId); | |
console.log("Preview URL: %s", mailer.getTestMessageUrl(info)); | |
return json({ result: 'OK' }) | |
} | |
export default function Page() { | |
let data = useActionData(); | |
console.log(data); | |
const onClick = async function(){ | |
} | |
return ( | |
<div className="remix__page"> | |
<main> | |
<h2>mail ,test</h2> | |
<hr /> | |
<Form method="post" name="form1" className="remix__form"> | |
<label> | |
<div>to_mail:</div> | |
<input type="text" id="to_mail" name="to_mail" className="form-control" /> | |
</label> | |
<div> | |
<button type="submit">Submit</button> | |
</div> | |
</Form> | |
</main> | |
</div> | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app/lib/mailer.ts | |
const mailer = require("nodemailer"); | |
export default mailer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment