大佬教程收集整理的这篇文章主要介绍了AWS Simple Email Service + Nodemailer = 在开发和生产中没有错误——在开发中即时交付——但在生产中没有任何交付?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直无法确定在 NextJs 中使用 SES + Nodemailer 发送电子邮件的生产和开发之间可能存在的脱节。但是,我似乎无法确定发生了什么,因为我的 SES 控制台中没有反弹,也没有错误记录到开发控制台或生产中的实时无服务器功能日志。可以在 here
找到该存储库任何见解将不胜感激。
客户端表单,@components/Portals/nodemail.tsx@H_450_7@
import { input,button,Textarea,logo,ModalBACkdrop } from '@components/UI';
import { useState,SyntheticEvent,FC,useEffect,useCallBACk } from 'react';
import { useUI } from '@components/context';
import CSS from './contact-us.module.CSS';
import cn from 'classnames';
import { valIDEmail } from '@lib/valIDate-email';
const SendEmail: FC = () => {
const { setModalVIEw } = useUI();
const [inputE1,seTinputE1] = useState('');
const [inputE2,seTinputE2] = useState('');
const [inputE3,seTinputE3] = useState('');
const [inputE4,seTinputE4] = useState('');
// const inputText = useRef<HTMLTextAreaElement>(null);
const [dirty,setDirty] = useState(false);
const [message,setmessage] = useState('');
const [Disabled,setDisabled] = useState(false);
const [loading,setLoading] = useState(false);
const userSend = async (e: SyntheticEvent<EventTarget>) => {
e.preventDefault();
// const prod = `drisdell.org/API/nodemailer`;
// const dev = '/API/nodemailer';
if (!dirty && !Disabled) {
setDirty(true);
handleValIDation();
}
setLoading(true);
setmessage('');
let res = await fetch('/API/nodemailer',{
body: JsON.Stringify({
text: inputE3,subject: inputE4,name: inputE2,email: inputE1
}),headers: {
Accept: 'application/Json,text/plain,*/*','Content-Type': 'application/Json'
},method: 'POST'
});
const { error,data } = await res.Json();
if (error) {
setmessage(error);
return;
}
setLoading(false);
seTinputE1('');
seTinputE2('');
seTinputE3('');
seTinputE4('');
setmessage(
'success ? email sent! We will get BACk to you within several business days' +
`${data}`
);
await setModalVIEw('succesS_VIEW');
};
const handleValIDation = useCallBACk(() => {
if (dirty) {
setDisabled(!valIDEmail(inputE1) || !inputE2 || !inputE3 || !inputE4);
}
},[inputE1,inputE2,inputE3,inputE4,dirty]);
useEffect(() => {
handleValIDation();
},[handleValIDation]);
return (
<form
onsubmit={userSenD}
classname={Cn('w-100 flex flex-col justify-between')}
>
<div classname='flex justify-center pb-4 '>
<logo classname='h-20 w-20 md:h-40 md:w-40 rounded-full' />
</div>
<div classname='relative max-w-xl mx-auto'>
<ModalBACkdrop />
{message && (
<div classname='text-white border border-white p-2 mb-2 rounded-2xl'>
{messagE}
</div>
)}
<label HTMLFor='email'>{'Email Address'}</label>
<input
ID='from-input'
name='from'
placeholder='user@example.net'
onChange={seTinputE1}
required={truE}
type='email'
classname='mb-2 bg-priMary-9 text-priMary-0 Font-medium focus:outline-none rounded-md'
/>
<label HTMLFor='name'>{'Full name'}</label>
<input
ID='name-input'
name='name'
placeholder='first & last names'
onChange={seTinputE2}
required={truE}
type='text'
classname='mb-2 bg-priMary-9 text-priMary-0 Font-medium focus:outline-none rounded-md'
/>
<label HTMLFor='subject'>{'Subject'}</label>
<input
ID='subject-input'
name='subject'
placeholder='Email subject...'
onChange={seTinputE4}
required={truE}
type='text'
classname='mb-2 bg-priMary-9 text-priMary-0 Font-medium focus:outline-none rounded-md'
/>
<label HTMLFor='text'>{'Body'}</label>
<Textarea
ID='text-textarea'
name='text'
placeholder='Email body...'
onChange={seTinputE3}
required={truE}
minLength={5}
cols={1}
classname='mb-2 bg-priMary-9 text-priMary-0 Font-medium focus:outline-none rounded-md'
/>
<div classname='w-auto px-8 flex flex-col'>
<button
type='submit'
variant='slim'
loading={loading}
Disabled={DisableD}
classname={Cn(
CSs.root,'my-4 w-auto max-w-sm bg-priMary-7 text-priMary-0 hover:bg-priMary-9 rounded-md duration-150 Transition-colors'
)}
>
{'submit EMAIL'}
</button>
</div>
<span classname='pt-1 text-center text-sm'>
<span classname='text-priMary-9'>Interested in a Career?</span>
<a
classname='text-priMary-9 Font-bold hover:underline cursor-pointer'
onClick={() => setModalVIEw('submit_RESUME_VIEW')}
>
submit a Resume
</a>
</span>
</div>
</form>
);
};
export default SendEmail;
@H_450_7@
pages/API/nodemailer.ts@H_450_7@
import nodemailer,{ SentmessageInfo } from 'nodemailer';
import { NextAPIrequest,NextAPIResponse } from 'next';
import secrets from 'aws';
import Mail from 'nodemailer/lib/mailer';
const {
SMTP_SENDER_ADDRESS,SMTP_RECIPIENt_address,SMTP_password,SMTP_USERname,SMTP_BCC_ADDRESS
} = secrets;
const senderAddress = SMTP_SENDER_ADDRESS;
const toaddress = SMTP_RECIPIENt_address;
const ccAddress = SMTP_SENDER_ADDRESS;
const bccAddress = SMTP_BCC_ADDRESS;
const smtpUsername = SMTP_USERname;
const smtppassword = SMTP_password;
export default async (req: NextAPIrequest,res: NextAPIResponsE) => {
const { text,subject,name,email } = req.body;
try {
const body_subject = `Contact Us Submission Event - ${subject}`;
const body_text = `Contact Us Form Submission via AWS SES & Nodemailer
---------------------------------------------------------
${text}
`;
const body_HTML = `<HTML>
<head></head>
<body>
<h1>${subject}</h1>
\n
<h2>name: ${name}</p>
\n
<h2>email: ${email}</h2>
\n
<p>${text}</p>
</body>
</HTML>`;
let transporter = nodemailer.createTransport({
host: 'email-smtp.us-east-2.amazonaws.com',port: 465,secure: true,auth: {
user: smtpUsername,pass: smtppassword
}
});
let mailOptions: Mail.options = {
sender: senderAddress,from: `${senderAddress}`,to: toaddress,cc: ccAddress,bcc: bccAddress,subject: body_subject,text: body_text,HTML: body_HTML
};
let response: SentmessageInfo = transporter.sendMail(
mailOptions,(info,err) => {
if (!err)
console.log(
'\n info.message: ',info?.message,'\n info.stack: ',info?.stack,'\n info.name: ',info?.name
);
console.log(err);
return info;
}
);
if (response === typeof Error) {
return res.status(400).Json({
error:
'There was an internal error ⚙... \n Shoot me an email at [Mary.Drisdell@drisdellconsulTing.com]'
});
}
return res.status(200).Json({ error: '',data: response ?? '' });
} catch (error) {
return res.status(500).Json({ error: error.message || error.toString() });
}
};
@H_450_7@
Vercel Dev CLI
- 在进行故障排除时,我遇到了
vercel dev@H_450_7@ 命令,该命令可在本地使用下一个框架在 vercel 环境中测试 API 路由。也就是说,我一直在使用这个新的开发脚本,它几乎可以立即交付到目标地址,而没有任何错误......
![AWS Simple Email Service + Nodemailer = 在开发和生产中没有错误——在开发中即时交付——但在生产中没有任何交付? AWS Simple Email Service + Nodemailer = 在开发和生产中没有错误——在开发中即时交付——但在生产中没有任何交付?](https://code.js-code.com/res/2022/05-25/21/5892c3727aa4152b464d4de0cb0ce5df.png)
Vercel 实时无服务器功能日志用于 /API/nodemailer 路由发送一封从未送达但也从未退回的电子邮件 ?
![AWS Simple Email Service + Nodemailer = 在开发和生产中没有错误——在开发中即时交付——但在生产中没有任何交付? AWS Simple Email Service + Nodemailer = 在开发和生产中没有错误——在开发中即时交付——但在生产中没有任何交付?](https://code.js-code.com/res/2022/05-25/21/fdfb18652e092afed888a0e49df232fa.png)
有什么想法吗?我已经尝试了几乎所有的方法,包括四重检查我在生产中的环境秘密。与 SES 的主域相关联的 DNS 记录匹配,我配置的 unlimited AWS SES Access@H_450_7@ ProgrAMMatic IAM 策略也是如此。任何帮助将不胜感激,因为我从上周末开始每天都在解决这个问题。
您可以发送电子邮件的现场制作站点是 here。
![image](res/2022/06-01/03/c201bd96e63a156036a289c51421f635.png)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
大佬总结
以上是大佬教程为你收集整理的AWS Simple Email Service + Nodemailer = 在开发和生产中没有错误——在开发中即时交付——但在生产中没有任何交付?全部内容,希望文章能够帮你解决AWS Simple Email Service + Nodemailer = 在开发和生产中没有错误——在开发中即时交付——但在生产中没有任何交付?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。