如果要解决一个简单的解决方案,我对代码进行道歉,但是我已经尝试了一段时间了,但是并没有得到它
import { Injectable } from '@nestjs/common';
import { MailerService } from '@nestjs-modules/mailer';
import { InjectRepository } from '@nestjs/typeorm';
import { ChecklistItemsEntity } from 'src/checklist-items/checklist-items.entity';
const mail = 'welcome'
@Injectable()
export class MailService {
constructor( public mailerService: MailerService) {}
public example(): void {
this
.mailerService
.sendMail({
to: 'ashwin.iyer01@gmail.com', // List of receivers email address
from: 'ashwin.iyer01@gmail.com', // Senders email address
subject: 'Testing Nest MailerModule ✔', // Subject line
text: 'welcome', // plaintext body
html: mail , // HTML body content
})
.then((success) => {
console.log(success)
})
.catch((err) => {
console.log(err)
});
}
这是我正在构建的应用程序的一部分,它按预期方式工作并发送示例电子邮件,但是我需要这些电子邮件包含应用程序链接到的MySQL数据库中的数据,而不是“欢迎”。 / p>
具体来说,我需要它包含数据库中一个实体表的所有记录(我正在使用TypeORM)。
我该怎么做?
答案 0 :(得分:0)
您应该能够只将Typeorm存储库添加到服务中,对数据进行查询,将数据序列化回HTML兼容格式,然后将其添加到html
或{{1 }}属性。甚至更好的是,您可以将text
注入到已经有MailService
的{{1}}之类的东西中,并创建一个函数来获取已经序列化的信息,然后从{{ 1}}致电UsertService
,然后从那里开始一切。