If you look at the documentation, the Alertmanager has a
to field, but nothing for CC or BCC. So how do you do those?
To explain this, we first need to dig into how email, and in particular the email protocol SMTP, works. There's two parts to sending an email, the envelope which consists of the commands used when talking to the SMTP server, and then the message (or data) containing the headers and body that you're used to seeing. This is similar to an postal mail, where there's what's written on the envelope and then what's written on the paper inside.
When sending an email there will be at least one
RCPT TO command, indicating where the email is to actually get sent to. For example if part of the SMTP exchange was
RCPT TO:<email@example.com> 250 OK RCPT TO:<firstname.lastname@example.org> 250 OK
then we'd be asking to send this email to email@example.com and firstname.lastname@example.org. The key point to understand is that at the SMTP level any
CC (carbon copy), or
BCC (blind carbon copy) headers inside the message don't affect the
RCPT TO which is where the email is actually going to be sent (though anti-spam systems may have opinions if they don't match).
If you're using a typical email client (a Mail User Agent or MUA if we're being precise) it'll handle things for you under the covers when it talks SMTP. Any addresses in
CC headers will be put in a
RCPT TO, and left in the message. Any addresses in
BCC headers will also be put in a
RCPT TO, however the
BCC headers will be be removed from the message.
What the Alertmanager offers is SMTP more than email. The Alertmanager will default the
To header to the value of the
to configuration field, but beyond that we're on our own. So here's a configuration fragment showing all of these used normally:
email_config: to: email@example.com,firstname.lastname@example.org,email@example.com headers: To: firstname.lastname@example.org CC: email@example.com
Here all three addresses are in the
to and will be sent the email, but only firstname.lastname@example.org and email@example.com will end up in the message headers.
From header, and
MAIL FROM SMTP commands work similarly. All of this can be used to have an email that says it was did one thing but actually did something else. That's generally considered abuse and/or spam though, so don't do that.
While the Alertmanager does offer you the power to craft the exact email you want, I'd recommend keeping things simple over doing complicated templating to get things perfect.
Any email addresses you wanted to CC, instead settle for having them in
To. So include them only in the
to field and don't specify explicit
CC headers, which has the same practical effect of sending to certain addresses and listing them in the headers. Instead of doing a BCC use one of the techniques to send a notification to a 2nd destination, which will also avoid the other recipients being aware of it.
Want to improve your notifications? Contact us.