(fastify: FastifyInstance)
| 17 | } |
| 18 | |
| 19 | export function emailQueueRoutes(fastify: FastifyInstance) { |
| 20 | // Create a new email queue |
| 21 | fastify.post( |
| 22 | "/api/v1/email-queue/create", |
| 23 | |
| 24 | async (request: FastifyRequest, reply: FastifyReply) => { |
| 25 | const { |
| 26 | name, |
| 27 | username, |
| 28 | password, |
| 29 | hostname, |
| 30 | tls, |
| 31 | serviceType, |
| 32 | clientId, |
| 33 | clientSecret, |
| 34 | redirectUri, |
| 35 | }: any = request.body; |
| 36 | |
| 37 | const mailbox = await prisma.emailQueue.create({ |
| 38 | data: { |
| 39 | name: name, |
| 40 | username, |
| 41 | password, |
| 42 | hostname, |
| 43 | tls, |
| 44 | serviceType, |
| 45 | clientId, |
| 46 | clientSecret, |
| 47 | redirectUri, |
| 48 | }, |
| 49 | }); |
| 50 | |
| 51 | // generate redirect uri |
| 52 | switch (serviceType) { |
| 53 | case "gmail": |
| 54 | const google = new OAuth2Client(clientId, clientSecret, redirectUri); |
| 55 | |
| 56 | const authorizeUrl = google.generateAuthUrl({ |
| 57 | access_type: "offline", |
| 58 | scope: "https://mail.google.com", |
| 59 | prompt: "consent", |
| 60 | state: mailbox.id, |
| 61 | }); |
| 62 | |
| 63 | tracking("gmail_provider_created", { |
| 64 | provider: "gmail", |
| 65 | }); |
| 66 | |
| 67 | reply.send({ |
| 68 | success: true, |
| 69 | message: "Gmail imap provider created!", |
| 70 | authorizeUrl: authorizeUrl, |
| 71 | }); |
| 72 | break; |
| 73 | case "other": |
| 74 | tracking("imap_provider_created", { |
| 75 | provider: "other", |
| 76 | }); |
no test coverage detected