我尝试使用 mailgun 发送电子邮件。我使用 node.js (nest.js),这是我的邮件服务。我应该改变什么?当我尝试发送第一封电子邮件(mailgun 官方网站中的描述)时,我收到了相同的错误消息。
import { Injectable } from '@nestjs/common';
import * as Mailgun from 'mailgun-js';
import { IMailGunData } from './interfaces/mail.interface';
import { ConfigService } from '../config/config.service';
@Injectable()
export class MailService {
private mg: Mailgun.Mailgun;
constructor(private readonly configService: ConfigService) {
this.mg = Mailgun({
apiKey: this.configService.get('MAILGUN_API_KEY'),
domain: this.configService.get('MAILGUN_API_DOMAIN'),
});
}
send(data: IMailGunData): Promise<Mailgun.messages.SendResponse> {
console.log(data);
console.log(this.mg);
return new Promise((res, rej) => {
this.mg.messages().send(data, function (error, body) {
if (error) {
console.log(error);
rej(error);
}
res(body);
});
});
}
}
当我尝试发送消息时,我收到带有禁止描述的 401 错误。
我的毫克 (console.log(this.mg))
Mailgun {
username: 'api',
apiKey: '920d6161ca860e7b84d9de75e14exxx-xxx-xxx',
publicApiKey: undefined,
domain: 'lokalne-dobrodziejstwa.pl',
auth: 'api:920d6161ca860e7b84d9de75e14exxx-xxx-xxx',
mute: false,
timeout: undefined,
host: 'api.mailgun.net',
endpoint: '/v3',
protocol: 'https:',
port: 443,
retry: 1,
testMode: undefined,
testModeLogger: undefined,
options: {
host: 'api.mailgun.net',
endpoint: '/v3',
protocol: 'https:',
port: 443,
auth: 'api:920d6161ca860e7b84d9de75e14exxx-xxx-xxx',
proxy: undefined,
timeout: undefined,
retry: 1,
testMode: undefined,
testModeLogger: undefined
},
mailgunTokens: {}
}
我的电子邮件正文
{
from: 'rejestracja@lokalne-dobrodziejstwa.pl',
to: 'me@gmail.com',
subject: 'Verify User',
html: '\n' +
' <h3>Hello me@gmail.com!</h3>\n' +
' '
}