gcp
The gcp output does up to two things for each email, in this order, each when its option is set:
storage: store the email, or a part of it, in a Google Cloud Storage bucket;pubsub: publish a CloudEvent describing the email to a Google Cloud Pub/Sub topic.
When to use it
Section titled “When to use it”Receive emails for your domain on Google Cloud: keep them in a bucket and trigger processing (a Cloud Run service, a Cloud Function) from the topic.
Credentials and project
Section titled “Credentials and project”The clients use Google Application Default Credentials and their project: the service account of the Cloud Run
service, GKE workload or VM, or the key file in GOOGLE_APPLICATION_CREDENTIALS. The output has no option for
them.
Cloud Storage
Section titled “Cloud Storage”storage.type selects what is stored:
type |
Stored object |
|---|---|
raw (default) |
the whole email; with addRawHeaders (default true), X-smtp-relay-* headers are added at the top: RCPT_TO (one per recipient of the flow), MAIL_FROM, USER (if authenticated), CLIENT_HOSTNAME and HELO |
attachments |
one object per attachment; put ${attachment} in path so they do not overwrite each other |
text |
the text body, if any |
html |
the HTML body, if any |
storage.path is the object name and accepts the path variables.
Pub/Sub
Section titled “Pub/Sub”pubsub.topic is the topic name. The message data is the CloudEvent, in JSON; pubsub.truncate sets the
maximum length of its subject, bodies and file names (8192 characters by default). The CloudEvent does not contain
the object name: use a name the consumer can rebuild from it, such as ${iso8601}_${id} (from its time and
data.server.id).
Options
Section titled “Options”Examples
Section titled “Examples”Store every email sent to mydomain.com and publish a CloudEvent:
{ "$schema": "https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json", "flows": { "localhost": { "filters": [ // Allow any ip to use the SMTP { "type": "whitelist", "to": ["regexp:.*@mydomain.com"] } ], "outputs": [ { "type": "gcp", // Store it in the bucket "storage": { "bucket": "myemail", "path": "${iso8601}_${id}.eml" }, // Send a message to the topic containing the bucket url if exist and the metadata of the email "pubsub": { "topic": "myemail" } } ] } }, // Listen on every interface so the server is reachable from outside its container "bind": "0.0.0.0", "options": { "disableReverseLookup": false, // Do not require auth "authOptional": true }}Store only the attachments, one folder per session:
$schema: https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.jsonflows: invoices: filters: - type: whitelist to: ["invoices@mydomain.com"] outputs: - type: gcp storage: bucket: mydomain-invoices type: attachments path: ${iso8601}_${id}/${attachment}bind: 0.0.0.0options: authOptional: true