Skip to content

Commit

Permalink
Replace hardcoded mail 'from' property (#231)
Browse files Browse the repository at this point in the history
This commit fixes the following error:
 - Message failed: 553 Relaying disallowed as [email protected]
@rubenhoenle already did a pr for this issue but it was for the main branch.
Thats why i created this commit on the next branch so a merge would be simpler.
  • Loading branch information
Kirari04 authored Feb 27, 2024
1 parent 4863443 commit bc72ec1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion apps/api/src/lib/nodemailer/auth/forgot-password.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export async function forgotPassword(
) {
try {
let mail;
let replyto;

const emails = await prisma.email.findMany();

Expand All @@ -27,6 +28,7 @@ export async function forgotPassword(
});
} else {
const email = emails[0];
replyto = email.reply;
mail = nodeMailer.createTransport({
// @ts-ignore
host: email.host,
Expand All @@ -42,7 +44,7 @@ export async function forgotPassword(
console.log("Sending email to: ", email);

let info = await mail.sendMail({
from: "[email protected]", // sender address
from: replyto, // sender address
to: email, // list of receivers
subject: `Password Reset Request`, // Subject line
text: `Password Reset Code: ${code}, follow this link to reset your password ${resetlink}`, // plain text body
Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/lib/nodemailer/ticket/assigned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { prisma } from "../../../prisma";
export async function sendAssignedEmail(email: any) {
try {
let mail;
let replyto;

const emails = await prisma.email.findMany();

Expand All @@ -20,6 +21,7 @@ export async function sendAssignedEmail(email: any) {
});
} else {
const email = emails[0];
replyto = email.reply;
mail = nodeMailer.createTransport({
// @ts-ignore
host: email.host,
Expand Down
4 changes: 3 additions & 1 deletion apps/api/src/lib/nodemailer/ticket/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export async function sendComment(
) {
try {
let mail;
let replyto;

console.log("Sending email to: ", email);

Expand All @@ -26,6 +27,7 @@ export async function sendComment(
});
} else {
const email = emails[0];
replyto = email.reply;
mail = nodeMailer.createTransport({
// @ts-ignore
host: email.host,
Expand All @@ -40,7 +42,7 @@ export async function sendComment(

await mail
.sendMail({
from: '"No reply 👻" [email protected]', // sender address
from: '"No reply 👻" ' + replyto, // sender address
to: email,
subject: `New comment on a ticket`, // Subject line
text: `Hello there, Ticket: ${title}, has had an update with a comment of ${comment}`, // plain text body
Expand Down
4 changes: 3 additions & 1 deletion apps/api/src/lib/nodemailer/ticket/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { prisma } from "../../../prisma";
export async function sendTicketCreate(ticket: any) {
try {
let mail;
let replyto;

const emails = await prisma.email.findMany();

Expand All @@ -20,6 +21,7 @@ export async function sendTicketCreate(ticket: any) {
});
} else {
const email = emails[0];
replyto = email.reply;
mail = nodeMailer.createTransport({
// @ts-ignore
host: email.host,
Expand All @@ -34,7 +36,7 @@ export async function sendTicketCreate(ticket: any) {

await mail
.sendMail({
from: '"No reply 👻" [email protected]', // sender address
from: '"No reply 👻" ' + replyto, // sender address
to: ticket.email,
subject: `Ticket ${ticket.id} has just been created & logged`, // Subject line
text: `Hello there, Ticket ${ticket.id}, which you reported on ${ticket.createdAt}, has now been created and logged`, // plain text body
Expand Down
4 changes: 3 additions & 1 deletion apps/api/src/lib/nodemailer/ticket/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { prisma } from "../../../prisma";

export async function sendTicketStatus(ticket: any) {
let mail;
let replyto;

const emails = await prisma.email.findMany();

Expand All @@ -19,6 +20,7 @@ export async function sendTicketStatus(ticket: any) {
});
} else {
const email = emails[0];
replyto = email.reply;
mail = nodeMailer.createTransport({
//@ts-ignore
host: email.host,
Expand All @@ -33,7 +35,7 @@ export async function sendTicketStatus(ticket: any) {

await mail
.sendMail({
from: "[email protected]", // sender address
from: replyto, // sender address
to: ticket.email,
subject: `Ticket ${ticket.id} status is now ${
ticket.isComplete ? "COMPLETED" : "OUTSTANDING"
Expand Down

0 comments on commit bc72ec1

Please sign in to comment.