合否基準:
参照:
@thinkingserious さん、こんにちは。
今年の #hacktoberfest の 4 つ目の PR を見つけようとしています。これらの限定ピンを見たので、試してみたいと思い
Sendgrid を使用したことがないので、どこから始めて問題を理解すればよいか少し迷っています。 メールヘルパーの拡張についてですか? 単一のメールを送信する方法を文書化していますか? いくつかの説明をお願いします。
乾杯、パブロ。
パブロさん、こんにちは。
まず、「Mail Helper Enhancement (v3 mail/send)」プロジェクト全体を見直すことをお勧めします。
メール ヘルパーをリファクタリングして、このプロジェクトで定義されているユース ケースをできるだけ簡単に実行できるようにしたいと考えています。
たとえば、単一の電子メールを送信するための hello world は次のようになります。
var helper = require('sendgrid').mail;
var from_email = new helper.Email('[email protected]');
var to_email = new helper.Email('[email protected]');
var subject = 'Hello World from the SendGrid Node.js Library!';
var content = new helper.Content('text/plain', 'Hello, Email!');
var mail = new helper.Mail(from_email, subject, to_email, content);
var sg = require('sendgrid')(process.env.SENDGRID_API_KEY);
var request = sg.emptyRequest({
method: 'POST',
path: '/v3/mail/send',
body: mail.toJSON(),
});
sg.API(request, function(error, response) {
console.log(response.statusCode);
console.log(response.body);
console.log(response.headers);
});
それを改善する 1 つの方法は次のとおりです。
var mail = require('sendgrid').mail;
mail.AddFromEmail('[email protected]');
mail.AddToEmail('[email protected]');
mail.AddSubject('Hello World from the SendGrid Node.js Library!');
mail.AddContent('text/plain', 'Hello Email!');
var sendgrid = require('sendgrid')(process.env.SENDGRID_API_KEY);
sendgrid.send(mail, function(error, response) {
if(error) {
console.log(error.message);
console.log(error.response.statusCode);
console.log(error.response.body);
console.log(error.response.headers);
} else {
console.log(response);
}
});
OK、完全なリファクタリングです。 時間を見つけて挑戦してみたいと思います。
ここで進行中: #378
最も参考になるコメント
パブロさん、こんにちは。
まず、「Mail Helper Enhancement (v3 mail/send)」プロジェクト全体を見直すことをお勧めします。
メール ヘルパーをリファクタリングして、このプロジェクトで定義されているユース ケースをできるだけ簡単に実行できるようにしたいと考えています。
たとえば、単一の電子メールを送信するための hello world は次のようになります。
それを改善する 1 つの方法は次のとおりです。