-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* tst * updated to gotify for contact forms * clean-up * clean-up * Use dynamic ENV * Use only ArmIT email and not personal --------- Co-authored-by: Oscar Eriksson <oscariremma@gmail.com>
- Loading branch information
1 parent
10c61fd
commit a8a2a94
Showing
4 changed files
with
40 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
GOTIFY_URL=http://gotify/mail | ||
GOTIFY_TOKEN=gotify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,41 @@ | ||
// src/routes/contact/+page.server.js | ||
import nodemailer from 'nodemailer'; | ||
import { env } from '$env/dynamic/private' | ||
|
||
export const actions = { | ||
default: async ({ request }) => { | ||
const form = await request.formData(); | ||
const email = form.get('e-mail'); | ||
|
||
let transporter = nodemailer.createTransport({ | ||
service: 'Gmail', | ||
auth: { | ||
user: 'motin@chalmers.it', | ||
pass: 'bcsvlrwvobdfacwg' | ||
} | ||
}); | ||
|
||
// Can change this in the future if u want: | ||
let mailOptions = { | ||
from: '"Armit (Contact ME)" <motin@chalmers.it>', | ||
to: 'armit@chalmers.it, motin@chalmers.it', | ||
from: '"Armit (Contact ME)" <armit@chalmers.it>', | ||
to: 'armit@chalmers.it', | ||
subject: '💃💃Contact ME Form', | ||
text: "Please reach out to me at: " + email | ||
}; | ||
|
||
try { | ||
await transporter.sendMail(mailOptions); | ||
const info = await fetch(env.GOTIFY_URL, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Authorization': 'pre-shared: ' + env.GOTIFY_TOKEN | ||
}, | ||
body: JSON.stringify(mailOptions) | ||
}); | ||
|
||
return { | ||
status: 200 | ||
}; | ||
} catch (error) { | ||
console.error('Failed to send email:', error); | ||
console.log('Message sent: %s', info.messageId); | ||
|
||
} catch (error) { | ||
console.error('Error occurred while sending email:', error); | ||
return { | ||
status: 500, | ||
errors: { message: 'Failed to send email' } | ||
}; | ||
} | ||
return { | ||
status: 200 | ||
}; | ||
|
||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters