Skip to content

gcp

The gcp output does up to two things for each email, in this order, each when its option is set:

  1. storage: store the email, or a part of it, in a Google Cloud Storage bucket;
  2. pubsub: publish a CloudEvent describing the email to a Google Cloud Pub/Sub topic.

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.

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.

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.

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).

OptionTypeDescription
namestring

Name of the component, used in the logs and the output metrics, defaults to <type>_<position in the list>

pubsubobject

Publish a CloudEvent describing the email to a Google Cloud Pub/Sub topic, after storage when both are set

pubsub.topicrequiredstring

Name of the Google Cloud Pub/Sub topic to publish to

pubsub.truncatenumber
default 8192

Maximum length of the subject, text, html, attachment file names and client hostname in the CloudEvent, longer values are truncated

storageobject

Store the email, or a part of it, in a Google Cloud Storage bucket

storage.addRawHeadersboolean
default true

Prepend X-smtp-relay-* headers to a raw email before storing it: the envelope recipients (RCPT_TO), the envelope sender (MAIL_FROM), the authenticated user (USER), the client hostname (CLIENT_HOSTNAME) and the HELO name (HELO)

Only used when type is raw

storage.bucketrequiredstring

Name of the bucket to write to

storage.pathrequiredstring

Key of the object to write within the bucket

Variables written as ${name} are replaced: ${iso8601}, ${timestamp}, ${id}, ${messageId}, ${from}, ${subject}, ${to}, and ${attachment} (the attachment file name) when type is attachments. Use ${attachment} or ${id} to avoid overwriting objects

storage.type"raw" | "attachments" | "text" | "html"
default "raw"

Part of the email to save

raw: the whole email as received by our SMTP attachments: any files attached to the email, one object per attachment, ignoring emails without attachments text: The text content of the email if it exists html: The html content of the email if it exists

typerequired"gcp"

Type of the component

Store every email sent to mydomain.com and publish a CloudEvent:

configs/mail2gcp.jsonc
{
"$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:

attachments2gcs.yaml
$schema: https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json
flows:
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.0
options:
authOptional: true