mirror of
https://github.com/Feuerhamster/mailform.git
synced 2025-04-29 18:26:53 +02:00
add subject-prefix, fixes #7
This commit is contained in:
parent
ecfe351e17
commit
f160038984
5 changed files with 19 additions and 2 deletions
|
@ -83,6 +83,7 @@ They are JSON files placed in the `/targets` directory.
|
||||||
- `origin` *optional* | A HTTP origin that is used for CORS and to restrict access. Default is * if not set.
|
- `origin` *optional* | A HTTP origin that is used for CORS and to restrict access. Default is * if not set.
|
||||||
- `recipients` *required* | An array of email addresses which should receive the email.
|
- `recipients` *required* | An array of email addresses which should receive the email.
|
||||||
- `from` *optional* | The "from" field of an email. This is used as fallback if no "from" is provided in the request.
|
- `from` *optional* | The "from" field of an email. This is used as fallback if no "from" is provided in the request.
|
||||||
|
- `subjectPrefix` *optional* | A target-wide prefix for the email subject.
|
||||||
- `key` *optional* | A string used as API key if you want to restrict access to this target.
|
- `key` *optional* | A string used as API key if you want to restrict access to this target.
|
||||||
- `redirect` *optional*:
|
- `redirect` *optional*:
|
||||||
- `success` *optional*: A valid URL to redirect the user if the mail was sent successful.
|
- `success` *optional*: A valid URL to redirect the user if the mail was sent successful.
|
||||||
|
@ -103,6 +104,7 @@ Whether as formular data or json, the fields are the same.
|
||||||
- `from` *optional* | The email address of the sender. If this filed is not set, the "from" field of your target will be used.
|
- `from` *optional* | The email address of the sender. If this filed is not set, the "from" field of your target will be used.
|
||||||
- `firstName` *optional* | A classic first name filed which will be attached to the "from" field of the email.
|
- `firstName` *optional* | A classic first name filed which will be attached to the "from" field of the email.
|
||||||
- `lastName` *optional* | A classic last name filed which will be attached to the "from" field of the email.
|
- `lastName` *optional* | A classic last name filed which will be attached to the "from" field of the email.
|
||||||
|
- `subjectPrefix` *optional* | A Prefix for the email subject.
|
||||||
- `subject` *required* | The email subject.
|
- `subject` *required* | The email subject.
|
||||||
- `body` *required* | The email body (supports HTML).
|
- `body` *required* | The email body (supports HTML).
|
||||||
|
|
||||||
|
@ -131,6 +133,7 @@ If you use an API request, you have to fill it manually.
|
||||||
<input type="email" name="from" placeholder="Sender's email address"/>
|
<input type="email" name="from" placeholder="Sender's email address"/>
|
||||||
<input type="text" name="firstName" placeholder="First name" />
|
<input type="text" name="firstName" placeholder="First name" />
|
||||||
<input type="text" name="lastName" placeholder="Last name" />
|
<input type="text" name="lastName" placeholder="Last name" />
|
||||||
|
<input type="hidden" name="subjectPrefix" value="[App-Question] " />
|
||||||
<input type="text" name="subject" placeholder="Subject" />
|
<input type="text" name="subject" placeholder="Subject" />
|
||||||
<div class="g-recaptcha" data-sitekey="your_site_key"></div>
|
<div class="g-recaptcha" data-sitekey="your_site_key"></div>
|
||||||
<textarea name="body" placeholder="Your message"></textarea>
|
<textarea name="body" placeholder="Your message"></textarea>
|
||||||
|
|
|
@ -3,6 +3,7 @@ export interface Target {
|
||||||
origin: string;
|
origin: string;
|
||||||
recipients: string[];
|
recipients: string[];
|
||||||
from?: string;
|
from?: string;
|
||||||
|
subjectPrefix?: string;
|
||||||
redirect?: Redirects;
|
redirect?: Redirects;
|
||||||
key?: string;
|
key?: string;
|
||||||
rateLimit?: TargetRateLimit;
|
rateLimit?: TargetRateLimit;
|
||||||
|
|
|
@ -20,6 +20,14 @@ export const postBody = {
|
||||||
maximum: 100
|
maximum: 100
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
subjectPrefix: {
|
||||||
|
type: "string",
|
||||||
|
presence: false,
|
||||||
|
length: {
|
||||||
|
minimum: 1,
|
||||||
|
maximum: 255
|
||||||
|
}
|
||||||
|
},
|
||||||
subject: {
|
subject: {
|
||||||
type: "string",
|
type: "string",
|
||||||
presence: { allowEmpty: false },
|
presence: { allowEmpty: false },
|
||||||
|
|
|
@ -19,6 +19,10 @@ export const targetModel = {
|
||||||
type: "string",
|
type: "string",
|
||||||
presence: false
|
presence: false
|
||||||
},
|
},
|
||||||
|
subjectPrefix: {
|
||||||
|
type: "string",
|
||||||
|
presence: false
|
||||||
|
},
|
||||||
redirect: {
|
redirect: {
|
||||||
type: "object",
|
type: "object",
|
||||||
presence: false
|
presence: false
|
||||||
|
|
|
@ -90,12 +90,13 @@ router.post("/:target", async (req: Request, res: Response) => {
|
||||||
const fieldFrom = fields["from"] instanceof Array ? fields["from"][0] : fields["from"]
|
const fieldFrom = fields["from"] instanceof Array ? fields["from"][0] : fields["from"]
|
||||||
const fieldFirstName = fields["firstName"] instanceof Array ? fields["firstName"][0] : fields["firstName"]
|
const fieldFirstName = fields["firstName"] instanceof Array ? fields["firstName"][0] : fields["firstName"]
|
||||||
const fieldLastName = fields["lastName"] instanceof Array ? fields["lastName"][0] : fields["lastName"]
|
const fieldLastName = fields["lastName"] instanceof Array ? fields["lastName"][0] : fields["lastName"]
|
||||||
const fieldSubject = fields["subject"] instanceof Array ? fields["subject"][0] : fields["subject"]
|
const fieldSubjectPrefix = fields["subjectPrefix"] instanceof Array ? fields["subjectPrefix"][0] : fields["subjectPrefix"] ?? ""
|
||||||
|
const subject = (target.subjectPrefix ?? "") + fieldSubjectPrefix + (fields["subject"] instanceof Array ? fields["subject"][0] : fields["subject"])
|
||||||
const fieldBody = fields["body"] instanceof Array ? fields["body"][0] : fields["body"]
|
const fieldBody = fields["body"] instanceof Array ? fields["body"][0] : fields["body"]
|
||||||
|
|
||||||
// send email
|
// send email
|
||||||
let from = EmailService.formatFromField(fieldFrom ?? target.from, fieldFirstName, fieldLastName);
|
let from = EmailService.formatFromField(fieldFrom ?? target.from, fieldFirstName, fieldLastName);
|
||||||
let sent = await EmailService.sendMail(req.params.target, from, fieldSubject, fieldBody, files);
|
let sent = await EmailService.sendMail(req.params.target, from, subject, fieldBody, files);
|
||||||
|
|
||||||
if(sent instanceof Error || !sent) {
|
if(sent instanceof Error || !sent) {
|
||||||
if(target.redirect?.error) return res.redirect(target.redirect.error);
|
if(target.redirect?.error) return res.redirect(target.redirect.error);
|
||||||
|
|
Loading…
Add table
Reference in a new issue