我需要在Linux服务器上进行通知发送者。这个想法是每周一次,此发件人在JQL中进行查询,如果返回某些内容,则将电子邮件发送到某个列表。我是服务器和JavaScript的新手。我已经在做JQL查询,但是:
- 我需要发件人知道正确的时间。触发发件人的最有效方法是什么?
- 如何将JS中的电子邮件从特定地址发送到电子邮件列表?
粗略的草图:
//magic, part 1
WaitUntilMonday();
var result = DoJQLQuery();
if (result != '')
SendNotificationEmail(from,to,message);
//magic, part 2
我试图搜索它,但我不知道从哪里开始。我也感谢您也建议阅读材料。谢谢。
嗯,您可以将NODEJS与SendGrid API一起使用用于服务器端和电子邮件API。实际客户端,您可以将其连接到网站上的一个,也可以只是运行Nodejs应用程序。因此,起点是https://nodejs.org/和http://sendgrid.com那肯定会满足您的电子邮件需求。这是我使用的API密钥剥离的功能(显然),后邮件的呼叫实际发送了邮件,其余的就是验证。发送电子邮件非常简单。祝你好运。
const SENDGRID_API_KEY = "SG.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
var helper = require('sendgrid').mail;
var sg = require('sendgrid')(SENDGRID_API_KEY);
var emptyRequest = require('sendgrid-rest').request;
var request = require("request");
function makeEmail(whereFrom, whereTo, mysubject, mycontent){
from_email = new helper.Email(whereFrom);
to_email = new helper.Email(whereTo);
subject = mysubject;
content = new helper.Content("text/html", mycontent);
mail = new helper.Mail(from_email, subject, to_email, content);
custom_arg = new helper.CustomArgs("OURGUID", "ourcustomarg");
mail.addCustomArg(custom_arg);
var finished = mail.toJSON();
var timer = 0;
function postEmail(){
var requestBody = finished;
var requestPost = JSON.parse(JSON.stringify(emptyRequest));
requestPost.method = 'POST';
requestPost.path = '/v3/mail/send';
requestPost.body = requestBody;
sg.API(requestPost, function (error, response) {
console.log(response.statusCode + ' STATUS')
console.log('MESSAGE ID = '+ response.headers['x-message-id'])
if(response.statusCode == '202') {
console.log(response.statusCode + ' EMAIL SENT TO SENDGRID AND QUED')
}//response if statement
if(response.statusCode != '202'){
console.log(response.statusCode + ' Something went wrong')}
})//end internal api function
}//end api
postEmail(finished);//actually sending the mail
function getEmail(){
var requestBody = finished;
var requestPost = JSON.parse(JSON.stringify(emptyRequest));
requestPost.method = 'GET';
requestPost.path = '/v3/mail/send';
requestPost.body = requestBody;
sg.API(requestPost, function (error, response) {
console.log(response.statusCode + ' SUCCESSFUL EMAIL');
console.log('MESSAGE ID = '+ response.headers['x-message-id']) ;
})//end internal api function
}//end api
function checkBounce(){
console.log('this is checkBounce');
var options = { method: 'GET',
url: 'https://api.sendgrid.com/v3/suppression/bounces/'+ whereTo,
headers: { authorization: 'Bearer your api key here' },
body: '{}' };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(response.statusCode);
console.log(body);
});
}//check Bounce
function checkInvalid(){
console.log('This is check invalid');
var options = { method: 'GET',
url: 'https://api.sendgrid.com/v3/suppression/invalid_emails'+ whereTo,
headers: { authorization: 'Bearer your api key here' },
body: '{}' };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(response.statusCode);
console.log(body);
});
}//check Invalid
function checkBlock(){
console.log('This is check Block');
var options = { method: 'GET',
url: 'https://api.sendgrid.com/v3/suppression/blocks'+ whereTo,
headers: { authorization: 'Bearer your api key here' },
body: '{}' };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(response.statusCode);
console.log(body.created);
});
}//check Block
function checkTest(){
console.log('This is check Test');
var options = { method: 'GET',
url: 'https://api.sendgrid.com/v3/',
headers: { authorization: 'Bearer your api key here' },
body: '{}' };
request(options, function (error, response, body) {
if (error) throw new Error(error);
body = JSON.parse(body);
console.log(response.statusCode);
console.log(body);
});//end request
}//check Processed
}//make email end