Gratilaus Form 1.0.0

Choose your language.

言語を選んでください。

English

Gratilaus Form quick start

A guide to follow once, from top to bottom, the first time you use Gratilaus Form.
It takes you from your site's contact form to a message in your own inbox.
For the commands and how to fix common errors, see QUICK_REFERENCE.md.
Every setting is described in README.md.

0. What you need

  • An AWS account.
  • The AWS CLI and the AWS SAM CLI. Install both by AWS's own instructions (the SAM CLI needs Python 3.10 or later).
  • A profile the AWS CLI can sign in with (made with aws configure, aws login or similar).
  • Python 3.14. Without it, Docker can do the same job (step 4).
  • An email address of your own to receive the messages.

Cost: you pay for what you use of API Gateway, Lambda, SES and CloudWatch Logs.
For a contact form this is often small, but check the amounts on each service's pricing page.
The number of requests has a limit (THROTTLE_RATE_LIMIT), which also bounds the cost if the form is abused.

Time: confirming a sender address only takes a click on the link in an email.
Confirming a domain means waiting for DNS to spread.

The commands are written for macOS and Linux. Where Windows differs, it is shown.

1. Go into the folder

Unzip the download and go into its folder in the terminal. Change 1.0.0 to the version number in the zip's name.

cd ~/Downloads/gratilaus-form-1.0.0

2. Check the tools and the sign-in

<profile> is the name of the AWS profile you use.

aws --version
sam --version
python3.14 --version
aws sts get-caller-identity --profile <profile>

On Windows, use python --version for the third line, in a terminal where a Python 3.14 virtual environment is active: deploy.cmd looks for python3.14 or python, not for py.

What success looks like: each prints a version number. The last command prints a line with "Account".
If python3.14 is missing, write SAM_USE_CONTAINER="1" in step 4 (this needs Docker).

3. Prepare the sending of mail (SES)

SES sends only from an address (SES_FROM_EMAIL) that it has "verified".
Prepare it in one of these two ways, in the same Region as AWS_REGION in step 4.

A. Verify an email address (works without a domain of your own)

  1. In the AWS console, open SES and choose Identities → Create identity → Email address.
  2. Enter the sender address and create it. Click the link in the email that arrives at that address (the link expires after 24 hours).
  3. If the receiving address (NOTIFICATION_EMAIL) is another address, verify it the same way.

B. Verify a domain (when you have a domain of your own)

Write the domain in SES_DOMAIN_IDENTITY in step 4, and the deployment sets up the domain's verification.

  • If the domain's DNS is Route 53, write the hosted zone's ID in SES_DOMAIN_HOSTED_ZONE_ID. The DNS records for the verification are made for you too.
  • With other DNS, add the three records in the SesDkimRecords output, shown after the deployment, to your DNS yourself.

About the sandbox: in a new account, SES is in the "sandbox" and sends only to verified addresses.
This form sends mail to NOTIFICATION_EMAIL only (never to the visitor).
So once NOTIFICATION_EMAIL is verified, it works in the sandbox.
The sandbox allows 200 messages in 24 hours and 1 a second. For more, request production access in the SES console.

4. Make the settings file

Copy the sample. On Windows: copy deploy.conf.example conf\mysite.conf.

cp deploy.conf.example conf/mysite.conf

Open conf/mysite.conf and change the following. Keep each value in the form KEY="value".

SettingWhat to write
AWS_PROFILEThe profile's name from step 2
AWS_REGIONThe Region to use (for example us-east-1). The same as in step 3
STACK_NAMEA name for this form: starting with a letter, letters, digits and - only, up to 56 characters (for example mysite-contact)
ALLOWED_ORIGINSThe address of the site the form is on, like https://www.example.org, with no / at the end. Separate several with ,
SITE_NAMEThe name put in the mail's subject
NOTIFICATION_EMAILThe address that receives the messages (one only)
SES_FROM_EMAILThe sender address (the one verified in step 3)
  • If you took way B in step 3, also write SES_DOMAIN_IDENTITY and SES_DOMAIN_HOSTED_ZONE_ID.
  • If python3.14 is missing, write SAM_USE_CONTAINER="1".
  • For a site in another language, write the eight settings that start with MSG_. They are the sentences visitors see. Left empty, they are in English. The file has a Japanese example of the eight lines, starting at # MSG_SUCCESS="送信しました。…". For a Japanese site, replace the eight empty lines below it, from MSG_SUCCESS="" to MSG_FORBIDDEN="", with the example's eight lines, without the # and the spaces at their start. For another language, write the same eight in that language.

5. Check the settings without calling AWS

PRINT_PARAMETER_OVERRIDES=1 ./deploy.sh --conf conf/mysite.conf

With this, nothing is made in AWS: the settings are checked and the values to be passed are printed.

On Windows (Command Prompt), run set PRINT_PARAMETER_OVERRIDES=1, then .\deploy.cmd --conf conf\mysite.conf.
Afterwards, run set PRINT_PARAMETER_OVERRIDES= to undo it.
In PowerShell, use $env:PRINT_PARAMETER_OVERRIDES="1" instead, and Remove-Item Env:PRINT_PARAMETER_OVERRIDES to undo it (set does not set it there, and the real deployment would run).

What success looks like: lines of Name="value", like AllowedOrigins="https://…", and no [ERROR].
After an [ERROR], the next line says how to fix it. See also "Common errors" in QUICK_REFERENCE.md.

6. Deploy

./deploy.sh --conf conf/mysite.conf

On Windows: .\deploy.cmd --conf conf\mysite.conf.

What success looks like: near the end, a line Endpoint: with a https://…/contact URL under it.
That URL is where the form sends to.

If you took way B in step 3, sending fails until the domain is "verified".
The deployment ends by showing a command to check that.

7. Connect the page

  • A site made with Gratilaus Site: write the URL from step 6 in mailform.endpoint in config/site.yaml, and build the site again. The contact page (content/contact) then sends to that URL.
  • A page of your own: copy the part of examples/contact.html (in Japanese: examples/contact.ja.html) between the markers (copy from here, copy to here) into your page.

    • Replace data-endpoint="MAILFORM_ENDPOINT_URL" with the URL from step 6.
    • Put frontend/mailform.js near your pages, and point <script src> at it.
    • The sentences on the screen can be changed with the attributes that start with data-msg-.

8. Send one test message

Send one message from the form on your site.

What success looks like: the screen shows the sent message (MSG_SUCCESS), and the mail arrives at NOTIFICATION_EMAIL.
Its subject carries SITE_NAME. A reply goes to the visitor's address.
The mail ends with the sender's IP address and browser. Say so in your privacy policy, or use the definition that leaves them out (examples/forms.contact-without-ip.json; see "Form definitions" in README.md).

If nothing arrives, or the screen shows an error, see "When mail does not arrive" in QUICK_REFERENCE.md.

9. To stop using it (cleaning up)

Delete this form's deployment (the stack).

aws cloudformation delete-stack --stack-name <STACK_NAME> --profile <profile> --region <Region>
aws cloudformation wait stack-delete-complete --stack-name <STACK_NAME> --profile <profile> --region <Region>

When the second line ends without printing anything, the deletion is done. These are left behind; delete them yourself if you do not need them.

  • The domain verification made in step 3, way B, and its three Route 53 records (kept on purpose, so they are not lost by mistake).
  • An S3 bucket named sam-artifacts-<account ID>-<Region> (where the deployment's files are kept).
  • A log group whose name starts with API-Gateway-Execution-Logs_.

If this stack made API Gateway's logging role, deleting the stack deletes that role too.
That stops the logs of other APIs in the same Region as well, so first read "About the account-level API Gateway setting" in README.md.

About the license: every page with the form, and every page that loads mailform.js, shows a one-line credit. The line under the form in examples/contact.html is an example.
On a site made with Gratilaus Site, the footer's credit is enough. The details are in "License" in README.md.

Back to the top

Gratilaus Form quick reference

A sheet to look things up in, from the second time on. The first time, start with QUICKSTART.md.
Every setting is described in README.md.

Commands

Run them in this folder. Replace each <…> with your own value.
On Windows, read ./deploy.sh as .\deploy.cmd, and / as \ in the paths of files (conf/mysite.conf), not in AWS names such as the log group.

To do thisRun
Check the settings without calling AWSPRINT_PARAMETER_OVERRIDES=1 ./deploy.sh --conf conf/mysite.conf
Check the form definition (no AWS call)./deploy.sh --conf conf/mysite.conf --check-forms
Compare the form definition with a page./deploy.sh --conf conf/mysite.conf --check-forms --html <the page's HTML>
Deploy (also after changing the settings)./deploy.sh --conf conf/mysite.conf
Read the log of the sendsaws logs tail /aws/lambda/<STACK_NAME>-handler --since 1h --profile <profile> --region <Region>
See the form's URL againaws cloudformation describe-stacks --stack-name <STACK_NAME> --query "Stacks[0].Outputs" --profile <profile> --region <Region>
Delete it (clean up)aws cloudformation delete-stack --stack-name <STACK_NAME> --profile <profile> --region <Region>

In the Windows Command Prompt, for the first line run set PRINT_PARAMETER_OVERRIDES=1, then .\deploy.cmd --conf conf\mysite.conf, and finally set PRINT_PARAMETER_OVERRIDES= to undo it. In PowerShell, use $env:PRINT_PARAMETER_OVERRIDES="1" and Remove-Item Env:PRINT_PARAMETER_OVERRIDES.

Every command ends with exit code 0 when it succeeds, --check-forms and PRINT_PARAMETER_OVERRIDES=1 included. deploy.sh and deploy.cmd end with 1 when they refuse a setting or a form definition (with a message, usually starting with [ERROR]), and otherwise with the exit code of the AWS CLI or AWS SAM CLI command that failed. Each test in tests/ ends with 0 when every check passes and with 1 otherwise.

The settings file

Make it by copying deploy.conf.example to conf/<name>.conf. Write each value as KEY="value".

SettingWhat it isNeeded?
AWS_PROFILE, AWS_REGIONThe profile to sign in with, and the RegionYes
STACK_NAMEA name for this form (starting with a letter; letters, digits and -; up to 56 characters)Yes
ALLOWED_ORIGINSThe address of the site the form is on (like https://www.example.org; separate several with ,)Yes
SITE_NAMEThe name put in the mail's subject (website when not set)No
NOTIFICATION_EMAILThe address that receives the messages (one only)Yes
SES_FROM_EMAILThe sender address (verified in SES)Yes
SES_REGIONOnly when SES is used in another RegionNo
SES_DOMAIN_IDENTITY, SES_DOMAIN_HOSTED_ZONE_IDWhen the deployment should set up the domain's verificationNo
MSG_SUCCESS and the other MSG_ settings (eight in all)The sentences visitors see. Empty means English. If you write them, write all eightYes, for a site in another language
FORMS_FILEA form definition (JSON) with fields of your own. The path counts from the settings file's folderNo
THROTTLE_RATE_LIMIT, THROTTLE_BURST_LIMITThe most requests accepted per secondNo
SAM_USE_CONTAINER"1" when Python 3.14 is missing (needs Docker)No

Where the sentences on the screen come from

WhereWhat it changes
The eight data-msg- attributes in the page's HTML (intro, no-endpoint, need-agree, confirm, sending, cancelled, bad-response, failed)Sentences decided in the browser (sending, the confirmation, a failed connection, and so on)
<label> and the like in the page's HTMLThe fields' names
The eight MSG_ settings in the settings fileSentences the server answers with after a send (sent, a mistake in the input, and so on)
messages in the FORMS_FILE definitionThe server's sentences when a definition is used (then only MSG_INVALID, MSG_FAILED and MSG_FORBIDDEN are read)

To send without the confirmation dialog, add data-confirm="off" to #mailform-root.

Your files and the product's files

To move to a new version, you keep your files and take the product's from the new version. If you edit a product file, you have to redo the edit at every new version, so change the fields and the sentences with a form definition and the MSG_ settings.

KindFiles
Yours (a new version does not replace them)Your settings files (conf/<name>.conf, made from deploy.conf.example), your form definitions (FORMS_FILE, such as conf/forms.json), and the pages of your site that carry the form
The product's (replaced when you move to a new version)lambda/, template.yaml, deploy.py, deploy.sh and deploy.cmd, deploy.conf.example, frontend/mailform.js, examples/, tests/, requirements.txt, LICENSE and NOTICE, AGENTS.md and the documents such as the README, .github/

.aws-sam/ is made again by every deployment; do not copy it to the new version. A copy of mailform.js on your site is replaced only when the CHANGELOG says it changed. The steps are in "Upgrading to a new version" in README.md.

When mail does not arrive

What the screen showsLikely causeWhat to do
That the form has no endpoint (data-msg-no-endpoint)The page has no URL to send toWith Gratilaus Site, write mailform.endpoint and build again. On a page of your own, write data-endpoint
That sending failed (data-msg-failed)The page's address is not in ALLOWED_ORIGINS (with and without www, and http and https, are different addresses), or the URL is wrongFix ALLOWED_ORIGINS and deploy again. The browser's developer tools show a detailed error starting with mailform: in the console
A sentence about the input (MSG_INVALID and others)The input did not pass the checksCorrect the input as the sentence says. After changing the fields, compare the definition with the page with --check-forms --html
The sentence for a failed send (MSG_FAILED)SES could not send (the sender or the receiver is not verified, or the Region differs), or there were too many requestsRead the log. A line with SES send_email failed gives the reason
The sentence for an unexpected answer (data-msg-bad-response)The URL points at something elseUse the …/contact URL the deployment printed
The sent sentence appears, but no mail arrivesThe mail went to the spam folderLook in the spam folder, and mark the mail as not spam at the receiving end
The same mail arrives twiceThe answer to the send had no Access-Control-Allow-Origin, so the visitor sent againCheck with the two curl commands in "After deploying, check this" in README.md

Common errors (deploy.sh)

MessageFix
[ERROR] configuration file not foundCheck the path after --conf. A list of the settings files you can use follows
[ERROR] NOTIFICATION_EMAIL still has the sample valueWrite your own address instead of the sample (the same for SES_FROM_EMAIL)
[ERROR] ALLOWED_ORIGINS still has the sample originsWrite your own site's address
[ERROR] not in the form a browser sends as OriginWrite it like https://www.example.org: lower case, with no / at the end and no path
[ERROR] … MSG_* value(s) set and … emptyWrite all eight MSG_ settings, or leave all eight empty
[ERROR] … is not an email addressCorrect the address
[ERROR] … takes one addressWrite one address. To reach several people, use forwarding at the receiving end
[ERROR] STACK_NAME starts with a letter and has only letters, digits and -Start with a letter, and use only letters, digits and - (no _)
[ERROR] … $ and ` are not supportedRemove the $ and ` from the value, or put the value in '...'
[ERROR] FORMS_FILE not foundLook at the path shown. The path counts from the settings file's folder (from a settings file in conf/, write forms.json for conf/forms.json)
[ERROR] Python 3.14 not foundInstall Python 3.14, or set SAM_USE_CONTAINER="1" (needs Docker)
[ERROR] aws not found / [ERROR] sam not foundInstall the AWS CLI or the AWS SAM CLI

Working with an AI coding agent

  • AGENTS.md in this folder gives AI coding agents (Codex, GitHub Copilot, Cursor, Claude Code and others) the rules for this project: which files to change, the license's credit, and what to leave to you.
  • Claude Code (v2.1.277 or later) reads AGENTS.md on its own only when there is no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in this folder or a folder above it. If you keep one, put the line @AGENTS.md at the top of your CLAUDE.md.
  • Gemini CLI reads GEMINI.md by default. Add "AGENTS.md" to context.fileName in its settings.json.

The license's credit

  • You may use, modify and redistribute it, including for commercial use, on the same terms as Apache-2.0 (the patent grant too). However, on top of the Apache-2.0 terms, every page with the form, and every page that loads mailform.js, must visibly show the line below (H.K. a link to https://hidekazu-konishi.com/) (Section 4A).
  • It is not added for you; add it yourself, usually under the form (the line under the form in examples/contact.html).

    <p class="mailform-credit">Gratilaus Form by <a href="https://hidekazu-konishi.com/" rel="nofollow">H.K.</a></p>
  • Visible means: on every screen size and color scheme, without a click or hover. Do not hide it with your CSS or scripts, do not make it smaller than the smallest other text in the same area, and keep a contrast of at least 4.5:1 against its background. The link has to take a visitor to https://hidekazu-konishi.com/.
  • A site made with Gratilaus Site shows Built with Gratilaus by H.K. in its footer, so it does not need this line.
  • The rules for rewording or translating it (it may not suggest that the author endorses the site), and what can stand in for the credit (the exemption), are in "License" in README.md.

Terms

TermMeaning
StackThe set of AWS parts made for this form (named by STACK_NAME). It is deleted as a whole too
ProfileThe name of the sign-in the AWS CLI uses (AWS_PROFILE)
RegionAn AWS location (us-east-1 is N. Virginia). Usually SES and the form are in the same Region; if not, set SES_REGION
SESAWS's mail sending service (Amazon Simple Email Service)
Verified (SES)SES has confirmed that the owner of the address (or domain) uses it. The sender must be verified
Sandbox (SES)The restricted state of SES in a new account: it sends only to verified addresses
EndpointThe URL the form sends to (the …/contact the deployment prints)
OriginThe https://host part of a page's address. Only the ones in ALLOWED_ORIGINS are accepted
PreflightThe request (OPTIONS) a browser makes before sending, to ask whether it may
HoneypotA field people cannot see, a trap that tells automated sends apart
CreditThe one line Gratilaus Form by H.K. on the pages with the form, a condition of the license

Back to the top

This page is made from QUICKSTART.md and QUICK_REFERENCE.md in this folder. Every feature and setting is described in README.md.

日本語

Gratilaus Form クイックスタート

初めての 1 回だけ、上から順に進めるための手順書です。
自分のサイトの問い合わせフォームから、自分のメールアドレスへ届くまでを進めます。
コマンドの一覧やエラーの直し方は QUICK_REFERENCE.ja.md にあります。
すべての設定の説明は README.ja.md にあります。

0. 必要なもの

  • AWS のアカウント。
  • AWS CLI と AWS SAM CLI。どちらも AWS の公式の手順で入れます(SAM CLI は Python 3.10 以降が要ります)。
  • AWS CLI で使える認証のプロファイル(aws configure や aws login などで作ります)。
  • Python 3.14。無いときは、Docker で代わりにできます(手順 4)。
  • 届け先にする自分のメールアドレス。

費用: API Gateway・Lambda・SES・CloudWatch Logs を、使った分だけ払います。
問い合わせのフォームの量ならわずかなことが多いですが、金額は各サービスの料金のページで確かめてください。
送信の回数には上限があり(THROTTLE_RATE_LIMIT)、悪用されたときの費用も抑えます。

かかる時間: 送信元のメールアドレスの確認は、届いたメールのリンクを押すだけです。
ドメインで確認するときは、DNS が広まるまで待ちます。

コマンドは macOS・Linux の形で書いています。Windows で違うところは、その都度書いています。

1. フォルダに入る

zip を展開し、ターミナルでそのフォルダに入ります。1.0.0 は、zip の名前にある版の番号に合わせます。

cd ~/Downloads/gratilaus-form-1.0.0

2. 道具と認証を確かめる

<プロファイル> は、使う AWS の認証のプロファイルの名前です。

aws --version
sam --version
python3.14 --version
aws sts get-caller-identity --profile <プロファイル>

Windows では、3 行目を python --version にし、Python 3.14 の仮想環境を有効にした状態で確かめます(deploy.cmd が探すのは python3.14 か python で、py は探しません)。

成功の見え方: どれも版の番号が出ます。最後のコマンドは、"Account" を含む行を出します。
python3.14 が無いときは、手順 4 で SAM_USE_CONTAINER="1" を書きます(Docker が要ります)。

3. メールの送信(SES)を準備する

送信元のアドレス(SES_FROM_EMAIL)は、SES で「検証済み」でないと送れません。
次のどちらかで準備します。手順 4 の AWS_REGION と同じリージョンで行います。

A. メールアドレスで確認する(独自ドメインが無くてもできる)

  1. AWS のコンソールで SES を開き、Identities → Create identity → Email address を選びます(日本語の表示では、それぞれに当たる項目です)。
  2. 送信元のアドレスを入れて作成します。そのアドレスに届いたメールのリンクを押します(リンクの期限は 24 時間です)。
  3. 受け取る側のアドレス(NOTIFICATION_EMAIL)が別のアドレスなら、それも同じように確認します。

B. ドメインで確認する(独自ドメインがあるとき)

手順 4 で SES_DOMAIN_IDENTITY にドメインを書くと、このフォームの設定がドメインの確認の手続きを作ります。

  • ドメインの DNS が Route 53 なら、SES_DOMAIN_HOSTED_ZONE_ID にホストゾーンの ID を書きます。確認用の DNS のレコードも自動で作ります。
  • ほかの DNS なら、デプロイの後に出る SesDkimRecords の 3 つのレコードを、自分で DNS に登録します。

サンドボックスについて: 新しいアカウントの SES は「サンドボックス」にあり、検証済みのアドレスにしか送れません。
このフォームは、NOTIFICATION_EMAIL だけにメールを送ります(訪問者には送りません)。
そのため、NOTIFICATION_EMAIL を検証済みにすれば、サンドボックスのままで使えます。
サンドボックスの上限は、24 時間に 200 通・1 秒に 1 通です。それを超えるときは、SES のコンソールから本番の利用を申請します。

4. 設定ファイルを作る

見本を写します。Windows では copy deploy.conf.example conf\mysite.conf です。

cp deploy.conf.example conf/mysite.conf

conf/mysite.conf を開き、次を書き換えます。値は KEY="値" の形のまま書きます。

項目書くもの
AWS_PROFILE手順 2 のプロファイルの名前
AWS_REGION使うリージョン(例: ap-northeast-1)。手順 3 と同じにします
STACK_NAMEこのフォームの名前。英字で始め、英数字と - だけで 56 文字まで(例: mysite-contact)
ALLOWED_ORIGINSフォームを置くサイトのアドレス。https://www.example.com の形で、最後に / を付けません。複数なら , で区切ります
SITE_NAMEメールの件名に付く名前
NOTIFICATION_EMAIL問い合わせを受け取るアドレス(1 つ)
SES_FROM_EMAIL送信元のアドレス(手順 3 で確認したもの)
  • 手順 3 を B で進めるときは、SES_DOMAIN_IDENTITY と SES_DOMAIN_HOSTED_ZONE_ID も書きます。
  • python3.14 が無いときは、SAM_USE_CONTAINER="1" と書きます。
  • 日本語のサイトでは、MSG_ で始まる 8 つの項目を書きます。 訪問者の画面に出る文です。何も書かないと英語で出ます。ファイルの中に、# MSG_SUCCESS="送信しました。…" から始まる日本語の例が 8 行あります。その下にある空の MSG_SUCCESS="" から MSG_FORBIDDEN="" までの 8 行を、行頭の # と空白を消した例の 8 行で置き換えます。

5. AWS を呼ばずに設定を確かめる

PRINT_PARAMETER_OVERRIDES=1 ./deploy.sh --conf conf/mysite.conf

この指定のときは、AWS に何も作らず、設定を検査して、渡す値を表示するだけです。

Windows(コマンドプロンプト)では、set PRINT_PARAMETER_OVERRIDES=1 を実行してから .\deploy.cmd --conf conf\mysite.conf を実行します。
終わったら set PRINT_PARAMETER_OVERRIDES= で元に戻します。
PowerShell では、代わりに $env:PRINT_PARAMETER_OVERRIDES="1" を使い、Remove-Item Env:PRINT_PARAMETER_OVERRIDES で戻します(PowerShell の set ではこの指定にならず、本当のデプロイが動きます)。

成功の見え方: AllowedOrigins="https://…" のような 名前="値" の行が並び、[ERROR] が出ません。
[ERROR] が出たら、その次の行に直し方が書いてあります。QUICK_REFERENCE.ja.md の「よくあるエラー」も見てください。

6. デプロイする

./deploy.sh --conf conf/mysite.conf

Windows では .\deploy.cmd --conf conf\mysite.conf です。

成功の見え方: 終わりのほうに Endpoint: の行が出て、その下に https://…/contact の URL が出ます。
この URL が、フォームの送信先です。

手順 3 を B で進めたときは、ドメインが「検証済み」になるまで送信は失敗します。
状態を確かめるコマンドが、デプロイの最後に表示されます。

7. ページにつなぐ

  • Gratilaus Site のサイト: config/site.yaml の mailform.endpoint に、手順 6 の URL を書いて、サイトを作り直します。お問い合わせのページ(content/contact)がその URL へ送ります。
  • 自分で作ったページ: examples/contact.ja.html(日本語。英語は examples/contact.html)の印(copy from here と copy to here)の間を、自分のページに写します。

    • data-endpoint="MAILFORM_ENDPOINT_URL" を、手順 6 の URL に置き換えます。
    • frontend/mailform.js をページの近くに置き、<script src> をその場所に合わせます。
    • 画面の文は data-msg- で始まる属性で変えられます(日本語のサイトなら日本語にします)。

8. 試しに 1 通送る

サイトのフォームから、1 通送ります。

成功の見え方: 画面に送信できた旨の文(MSG_SUCCESS)が出て、NOTIFICATION_EMAIL にメールが届きます。
件名には SITE_NAME が付きます。返信すると、訪問者のアドレスに届きます。
メールの最後には、送信者の IP アドレスとブラウザの種類が入ります。プライバシーポリシーにそのことを書くか、それらを除く定義(examples/forms.contact-without-ip.json)を使います(README.ja.md の「フォームの定義」)。

届かないとき、画面にエラーが出るときは、QUICK_REFERENCE.ja.md の「届かないとき」を見てください。

9. やめるとき(後片付け)

このフォームの設定(スタック)を消します。

aws cloudformation delete-stack --stack-name <STACK_NAME> --profile <プロファイル> --region <リージョン>
aws cloudformation wait stack-delete-complete --stack-name <STACK_NAME> --profile <プロファイル> --region <リージョン>

2 行目が何も出さずに終われば、消し終わっています。次のものは残ります。要らなければ自分で消します。

  • 手順 3 の B で作ったドメインの確認と、Route 53 の 3 つのレコード(誤って消えないように残す作りです)。
  • sam-artifacts-<アカウント ID>-<リージョン> という S3 バケット(デプロイに使ったファイルの置き場所)。
  • API-Gateway-Execution-Logs_ で始まるロググループ。

このスタックが API Gateway のログ用のロールを作っていた場合、スタックを消すとそのロールも消えます。
同じリージョンのほかの API のログも止まるので、README.ja.md の「API Gateway のアカウントレベル設定について」を先に読んでください。

ライセンスについて: フォームのあるページと、mailform.js を読み込むページには、クレジットを 1 行置きます。examples/contact.html のフォームの下の行がその例です。
Gratilaus Site で作ったサイトなら、フッターのクレジットで足ります。詳しくは README.ja.md の「ライセンス」にあります。

ページの先頭へ

Gratilaus Form クイックリファレンス

2 回目からの早見表です。初めての方は QUICKSTART.ja.md から始めてください。
すべての設定の説明は README.ja.md にあります。

コマンド

このフォルダの中で実行します。<…> は自分の値に置き換えます。
Windows では ./deploy.sh を .\deploy.cmd に読み替え、ファイルのパス(conf/mysite.conf)の / を \ に読み替えます(ロググループのような AWS の名前の / は読み替えません)。

したいことコマンド
AWS を呼ばずに設定を確かめるPRINT_PARAMETER_OVERRIDES=1 ./deploy.sh --conf conf/mysite.conf
フォームの定義を確かめる(AWS を呼ばない)./deploy.sh --conf conf/mysite.conf --check-forms
フォームの定義とページを突き合わせる./deploy.sh --conf conf/mysite.conf --check-forms --html <ページの HTML>
デプロイする(設定を変えたときも同じ)./deploy.sh --conf conf/mysite.conf
送信の記録(ログ)を見るaws logs tail /aws/lambda/<STACK_NAME>-handler --since 1h --profile <プロファイル> --region <リージョン>
送信先の URL をもう一度見るaws cloudformation describe-stacks --stack-name <STACK_NAME> --query "Stacks[0].Outputs" --profile <プロファイル> --region <リージョン>
消す(後片付け)aws cloudformation delete-stack --stack-name <STACK_NAME> --profile <プロファイル> --region <リージョン>

Windows のコマンドプロンプトでは、1 行目は set PRINT_PARAMETER_OVERRIDES=1 の後に .\deploy.cmd --conf conf\mysite.conf を実行し、最後に set PRINT_PARAMETER_OVERRIDES= で戻します。PowerShell では $env:PRINT_PARAMETER_OVERRIDES="1" と Remove-Item Env:PRINT_PARAMETER_OVERRIDES を使います。

どのコマンドも、うまくいけば終了コード 0 で終わります(--check-forms と PRINT_PARAMETER_OVERRIDES=1 も同じ)。deploy.sh と deploy.cmd は、設定やフォームの定義を断ったとき(メッセージつき。ふつうは [ERROR] で始まる)に 1、それ以外の失敗では、失敗した AWS CLI か AWS SAM CLI のコマンドの終了コードで終わります。tests/ の各テストは、すべて合格なら 0、そうでなければ 1 で終わります。

設定ファイルの項目

設定ファイルは deploy.conf.example を conf/<名前>.conf に写して作ります。値は KEY="値" の形で書きます。

項目中身要るか
AWS_PROFILE・AWS_REGION使う認証のプロファイルとリージョン必須
STACK_NAMEこのフォームの名前(英字で始め、英数字と - で 56 文字まで)必須
ALLOWED_ORIGINSフォームを置くサイトのアドレス(https://www.example.com の形・, 区切り)必須
SITE_NAMEメールの件名に付く名前(書かなければ website)任意
NOTIFICATION_EMAIL受け取るアドレス(1 つ)必須
SES_FROM_EMAIL送信元のアドレス(SES で検証済み)必須
SES_REGIONSES を別のリージョンで使うときだけ任意
SES_DOMAIN_IDENTITY・SES_DOMAIN_HOSTED_ZONE_IDドメインの確認をこのフォームに作らせるとき任意
MSG_SUCCESS ほか MSG_ の 8 項目訪問者の画面に出る文。空なら英語。書くなら 8 つ全部日本語のサイトでは必須
FORMS_FILE項目を自分で決めるフォームの定義(JSON)。パスは設定ファイルのあるフォルダから数える任意
THROTTLE_RATE_LIMIT・THROTTLE_BURST_LIMIT1 秒あたりの受け付けの上限任意
SAM_USE_CONTAINERPython 3.14 が無いとき "1"(Docker が要る)任意

画面の文を変える場所

場所変わる文
ページの HTML の data-msg- で始まる 8 つの属性(intro・no-endpoint・need-agree・confirm・sending・cancelled・bad-response・failed)ブラウザの中だけで決まる文(送信中・確認・通信の失敗など)
ページの HTML の <label> など項目の名前
設定ファイルの MSG_ の 8 項目送った後にサーバーが返す文(送信できた・入力の誤りなど)
FORMS_FILE の定義の messages定義を使うときの、サーバーが返す文(このときは MSG_INVALID・MSG_FAILED・MSG_FORBIDDEN だけが使われる)

送信の前の確認のダイアログを出さないときは、#mailform-root に data-confirm="off" を付けます。

自分のファイルと製品のファイル

新しい版に上げるときは、自分のものを残し、製品のものを新しい版から使います。製品のものを直すと、版を上げるたびに手で直し直すことになるので、項目と文は、フォームの定義と MSG_ の設定で変えてください。

区分ファイル
自分のもの(版を上げても置き換えない)自分の設定ファイル(conf/<名前>.conf。deploy.conf.example を写して作る)、フォームの定義(FORMS_FILE。conf/forms.json など)、フォームを置いた自分のサイトのページ
製品のもの(版を上げるときに置き換える)lambda/、template.yaml、deploy.py・deploy.sh・deploy.cmd、deploy.conf.example、frontend/mailform.js、examples/、tests/、requirements.txt、LICENSE・NOTICE、AGENTS.md と README などの文書、.github/

.aws-sam/ はデプロイのたびに作り直されるので、新しい版へ写しません。サイトに置いた mailform.js の写しは、CHANGELOG に変わったとあるときだけ置き換えます。上げ方の手順は、README.ja.md の「新しい版に上げる」にあります。

届かないとき

画面に出ること考えられる原因すること
送信先が未設定である旨(data-msg-no-endpoint)ページに送信先の URL が入っていないGratilaus Site なら mailform.endpoint を書いて作り直す。自分のページなら data-endpoint を書く
送信できなかった旨(data-msg-failed)ページのアドレスが ALLOWED_ORIGINS に無い(www の有無、http と https の違いも別のアドレス)。または URL の誤りALLOWED_ORIGINS を直してデプロイし直す。ブラウザの開発者ツールのコンソールに mailform: で始まる詳しいエラーが出る
入力の誤りの文(MSG_INVALID など)入力が検査を通らない文に従って入力を直す。項目を変えたときは --check-forms --html で定義とページを突き合わせる
送信に失敗した文(MSG_FAILED)SES で送れなかった(送信元か受け取る側が検証済みでない、リージョンが違う)。または送信が多すぎるログを見る。SES send_email failed の行に理由が出る
予期しない応答の文(data-msg-bad-response)送信先の URL が別のものを指している送信先の URL を、デプロイで出た …/contact の URL にする
送信できた文が出たのに届かない迷惑メールのフォルダに入った迷惑メールのフォルダを見る。受け取る側で迷惑メールでないと設定する
同じメールが 2 通届く送信の応答に Access-Control-Allow-Origin が無く、訪問者が送り直したREADME.ja.md の「デプロイ後に必ず見ること」の 2 つの curl で確かめる

よくあるエラー(deploy.sh)

出るメッセージ直し方
[ERROR] configuration file not found--conf の後のパスを確かめる。続けて、使える設定ファイルの一覧が出る
[ERROR] NOTIFICATION_EMAIL still has the sample value見本のアドレスを自分のアドレスにする(SES_FROM_EMAIL も同じ)
[ERROR] ALLOWED_ORIGINS still has the sample origins自分のサイトのアドレスにする
[ERROR] not in the form a browser sends as Originhttps://www.example.com の形にする。小文字で、最後の / とパスを付けない
[ERROR] … MSG_* value(s) set and … emptyMSG_ の 8 項目を全部書くか、全部空にする
[ERROR] … is not an email addressアドレスの書き間違いを直す
[ERROR] … takes one addressアドレスを 1 つにする。複数の人に届けるなら、受け取る側の転送を使う
[ERROR] STACK_NAME starts with a letter and has only letters, digits and -英字で始め、英数字と - だけにする(_ は使えない)
[ERROR] … $ and ` are not supported値から $ と ` を除くか、値を '...' で囲む
[ERROR] FORMS_FILE not found出たパスを見る。パスは設定ファイルのあるフォルダから数える(conf/ に置いた設定から conf/forms.json を指すなら forms.json と書く)
[ERROR] Python 3.14 not foundPython 3.14 を入れるか、SAM_USE_CONTAINER="1" にする(Docker が要る)
[ERROR] aws not found / [ERROR] sam not foundAWS CLI か AWS SAM CLI を入れる

AI のコーディングエージェントを使うとき

  • このフォルダーの AGENTS.md は、AI のコーディングエージェント(Codex・GitHub Copilot・Cursor・Claude Code など)に、このプロジェクトの決まりを伝えます。どのファイルを変えるか、ライセンスのクレジット、人に任せることです(英語)。
  • Claude Code(v2.1.277 以降)が AGENTS.md を自分で読むのは、このフォルダーとその上のフォルダーに CLAUDE.md・.claude/CLAUDE.md・CLAUDE.local.md のどれも無いときだけです。CLAUDE.md を使っているなら、その先頭に @AGENTS.md の 1 行を書きます。
  • Gemini CLI は、既定では GEMINI.md を読みます。settings.json の context.fileName に "AGENTS.md" を足します。

ライセンスのクレジット

  • 使う・改変する・再配布する・商用で使うことは、Apache-2.0 と同じ条件でできます(特許の許諾も同じです)。ただし、Apache-2.0 の条件に加えて、フォームのあるページと mailform.js を読み込むページに、下の 1 行(H.K. は https://hidekazu-konishi.com/ へのリンク)を見える形で表示することが必要です(第 4A 節)。
  • 自動では入らないので、自分で足します。ふつうはフォームの下です(examples/contact.html のフォームの下の行)。

    <p class="mailform-credit">Gratilaus Form by <a href="https://hidekazu-konishi.com/" rel="nofollow">H.K.</a></p>
  • 見える形とは: どの画面幅・配色でも、クリックやホバーなしで見えることです。自分の CSS やスクリプトで隠さず、同じ場所のいちばん小さい文字より小さくせず、背景とのコントラストを 4.5:1 以上にします。リンクは、押せば https://hidekazu-konishi.com/ に着くものにします。
  • Gratilaus Site で作ったサイトは、フッターに Built with Gratilaus by H.K. が出るので、この行は要りません。
  • 言い換え・翻訳の決まり(作者が推薦しているとほのめかす文にはできません)と、クレジットの代わりにできること(免除)は、README.ja.md の「ライセンス」にあります。

用語

用語意味
スタックこのフォームのために AWS に作る部品のまとまり(STACK_NAME の名前)。消すときもまとめて消す
プロファイルAWS CLI が使う認証の名前(AWS_PROFILE)
リージョンAWS の地域(ap-northeast-1 は東京)。ふつうは SES とフォームを同じリージョンにする(違うときは SES_REGION)
SESAWS のメールの送信のサービス(Amazon Simple Email Service)
検証済み(SES)SES が「このアドレス(またはドメイン)の持ち主が使っている」と確かめた状態。送信元には必須
サンドボックス(SES)新しいアカウントの SES の制限された状態。検証済みの宛先にしか送れない
エンドポイントフォームの送信先の URL(デプロイで表示される …/contact)
オリジンページのアドレスのうち https://ホスト名 の部分。ALLOWED_ORIGINS に書いたものからだけ受け付ける
プリフライトブラウザが送信の前に、送ってよいかを確かめる要求(OPTIONS)
ハニーポット人には見えない入力欄。自動の送信を見分けるための罠
クレジットフォームのあるページに置く Gratilaus Form by H.K. の 1 行。ライセンスの条件

ページの先頭へ

このページは、このフォルダーの QUICKSTART.ja.md と QUICK_REFERENCE.ja.md から作っています。すべての機能と設定の説明は README.ja.md にあります。