"@ sendgrid / mail"λ§ μ¬μ©νμ¬ "μλ λ°μ€"λͺ¨λλ₯Ό νμ±ννλ λ°©λ²
μλ νμΈμ @CrazyGentleMan ,
μ£μ‘ ν©λλ€ . mail_settings
μ΄λ΄ μ¬μΌν©λλ€. λ€μ μ μ°Έμ‘° μ© μ 체 νμ΄λ‘λμ
λλ€.
λλ μ΄κ²μ μ°λ¦¬μ λ°± λ‘κ·Έμ μΆκ°νμ΅λλ€.
μ΄ λ¬Έμ κ° λ°± λ‘κ·Έμμ μ°μ μμλ₯Ό μ»μΌλ €λ©΄ μΆκ° +1 λλ PRμ΄ νμν©λλ€. PRμ λ°μΌλ©΄ μ°μ μμκ° κ°μ₯ λμ΅λλ€.
κ°μ¬!
λ§μμ λ΄μ,
Elmer
"@ sendgrid / mail"μ "sandbox"λͺ¨λλ₯Ό μΆκ°νλ κ³νμ μ΄λ»κ² μ§νλκ³ μμ΅λκΉ?
ννΈ μλ λ°μ€λ₯Ό μ¬μ©νλ λμμ΄ μμ΅λκΉ?
κ°μ¬!
μμμ μΈκΈνλ―μ΄ μλ λ°μ€ λͺ¨λλ‘ μ μ‘ν μ μμ§λ§ μ¬μ© μ¬λ‘μ λͺ
μ μ μΌλ‘ νμλμ΄ μμ§ μμ΅λλ€. 보λ΄λ λ΄μ©μ λ³Έλ¬Έμμλ νλ μ€ νλλ mailSettings.sandboxMode.enable
μ
λλ€. μ΄ κ°μ trueλ‘ μ€μ νλ©΄ μ΄λ©μΌμ΄ μλ λ°μ€ λͺ¨λλ‘ μ μ‘λ©λλ€.
μλ₯Ό λ€λ©΄ :
import * as SendGrid from '@sendgrid/mail';
import { MailData } from '@sendgrid/helpers/classes/mail';
import { Email } from '../models';
import config from '../config';
export function send(email: Email): Promise<any> {
SendGrid.setApiKey(config.services.email.apiKey);
const mailSettings = config.services.email.options;
const data: MailData = {
...email,
...mailSettings
};
// This will send the email in sandbox mode
data.mailSettings.sandboxMode.enable = true;
return SendGrid.send(data);
}
μλ λ°μ€ λͺ¨λκ° νμ±ν λ κ²½μ° μ΄λ©μΌμ΄ λμ 보λμ νμλ©λκΉ?
@ victor-ponce,
λλ κ·Έλ κ² μκ°νμ§ μλλ€.
V3μ κ²½μ° λ€μμ μ€ λν«μ λλ€.
const sgMail = require ( '@ sendgrid / mail');
sgMail.setApiKey (process.env.SENDGRID_API_KEY);
const msg = {
λ°λ μ¬λ : '
λ³΄λΈ μ¬λ : ' [email protected] ',
μ λͺ© : 'Hello world',
ν μ€νΈ : 'Hello plain world!',
html : 'Hello HTML world!',
templateId : 'd-f43daeeaef504760851f727007e0b5d0',
dynamic_template_data : {
μ λͺ© : 'ν μ€νΈ ν νλ¦Ώ',
μ΄λ¦ : 'Some One',
λμ : 'λ΄λ²',
},
mail_settings : {
νμ±ν : μ°Έ
}
},
};
sgMail.send (msg);
κ°λ₯νμ§ μμ΅λκΉ? λ΄ νμ¬ sendgrid νμΌμ λ€μκ³Ό κ°μ΅λλ€.
import sgMail from '@sendgrid/mail';
const sendGridApiKey = process.env.SENDGRID_API_KEY;
if (!sendGridApiKey) {
throw new Error('The sendgrid api key has not been set in the environment variables');
}
sgMail.setApiKey(sendGridApiKey);
// I need to be able to do something like this
sgMail.enableSandbox(process.env.NODE_ENV !== 'production')
export { sgMail };
κ²°κ΅ sendgridλ₯Ό μ¬μ©νμ¬ μ€νΈλΌμ΄ν ν μ€νΈ ν€μ λ§€μ° μ μ¬ν μλ λ°μ€ API ν€λ₯Ό μμ± ν μ μλ€λ©΄ μ’μ κ²μ λλ€.
PRμ΄ λ³ν©λμ΄ λ¬Έμμ μΆκ°λμμ΅λλ€.
@malimccalla νμ¬ μ§μλμ§ μμ΅λλ€. μλ μμ²κ³Ό μμ ν λ€λ₯΄κΈ° λλ¬Έμμ΄λ₯Ό μΆμ νκΈ° μν΄ μ λ¬Έμ λ₯Ό μ΄ ββμ μμ΅λκΉ?
@ childish-sambino μλ£! # 1128
κ°μ₯ μ μ©ν λκΈ
μλ νμΈμ @CrazyGentleMan ,
μ£μ‘ ν©λλ€ .
mail_settings
μ΄λ΄ μ¬μΌν©λλ€. λ€μ μ μ°Έμ‘° μ© μ 체 νμ΄λ‘λμ λλ€.λλ μ΄κ²μ μ°λ¦¬μ λ°± λ‘κ·Έμ μΆκ°νμ΅λλ€.
μ΄ λ¬Έμ κ° λ°± λ‘κ·Έμμ μ°μ μμλ₯Ό μ»μΌλ €λ©΄ μΆκ° +1 λλ PRμ΄ νμν©λλ€. PRμ λ°μΌλ©΄ μ°μ μμκ° κ°μ₯ λμ΅λλ€.
κ°μ¬!
λ§μμ λ΄μ,
Elmer