Node.js အီးမေးလ်တစ်စောင်ပို့ပါ။
Nodemailer Module
Nodemailer module သည် သင့်ကွန်ပြူတာမှ အီးမေးလ်များ ပေးပို့ရန် လွယ်ကူစေသည်။
Nodemailer module ကို npm ကို အသုံးပြု၍ ဒေါင်းလုဒ်လုပ်ပြီး ထည့်သွင်းနိုင်သည်။
C:\Users\Your Name>npm install nodemailer
Nodemailer module ကို သင်ဒေါင်းလုဒ်လုပ်ပြီးနောက်၊ မည်သည့်အပလီကေးရှင်းတွင်မဆို module ထည့်သွင်းနိုင်သည်-
var nodemailer = require('nodemailer');
အီးမေးလ်တစ်စောင်ပို့ပါ။
ယခု သင့်ဆာဗာမှ အီးမေးလ်များ ပေးပို့ရန် အသင့်ဖြစ်နေပါပြီ။
အီးမေးလ်တစ်စောင်ပေးပို့ရန် သင်ရွေးချယ်ထားသော အီးမေးလ်ဝန်ဆောင်မှုပေးသူထံမှ သုံးစွဲသူအမည်နှင့် စကားဝှက်ကို အသုံးပြုပါ။ အီးမေးလ်တစ်စောင်ပေးပို့ရန် သင့် Gmail အကောင့်ကို အသုံးပြုနည်းကို ဤသင်ခန်းစာတွင် ပြသပါမည်။
ဥပမာ
var nodemailer = require('nodemailer');
var transporter =
nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: 'yourpassword'
}
});
var mailOptions = {
from: '[email protected]',
to: '[email protected]',
subject: 'Sending Email using Node.js',
text:
'That was easy!'
};
transporter.sendMail(mailOptions,
function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
ဒါပဲ! ယခု သင့်ဆာဗာသည် အီးမေးလ်များ ပေးပို့နိုင်ပါပြီ။
လက်ခံသူအများအပြား
လက်ခံသူ တစ်ဦးထက်ပိုသော အီးမေးလ်တစ်စောင် ပေးပို့ရန်၊ ကော်မာများဖြင့် ခြားထားသော mailOptions အရာဝတ္တု၏ "သို့" ပိုင်ဆိုင်မှုသို့ ပေါင်းထည့်ပါ-
ဥပမာ
လိပ်စာတစ်ခုထက်ပို၍ အီးမေးလ်ပို့ပါ-
var mailOptions = {
from: 'youremail@gmail.com',
to: '[email protected],
[email protected]',
subject: 'Sending Email using Node.js',
text:
'That was easy!'
}
HTML ပို့ပါ။
သင့်အီးမေးလ်တွင် HTML ဖော်မတ်ထားသည့် စာသားပေးပို့ရန်၊ "စာသား" ပိုင်ဆိုင်မှုအစား "html" ပိုင်ဆိုင်မှုကို အသုံးပြုပါ-
ဥပမာ
HTML ပါဝင်သော အီးမေးလ်ကို ပို့ပါ-
var mailOptions = {
from: 'youremail@gmail.com',
to: '[email protected]',
subject: 'Sending Email using Node.js',
html:
'<h1>Welcome</h1><p>That was easy!</p>'
}