Aug 30, 2019
Deploying Signals for On-Premises: PowerMTA Integration
Mari kita bahas detail pengaturan PowerMTA untuk Sinyal SparkPost. Anda akan membutuhkannya:
Host untuk menjalankan versi terbaru PowerMTA - baik yang baru, atau mesin yang sudah ada
A SparkPost account with API key permission for “Incoming Events: Write” seperti yang dijelaskan di sini
Kami akan menyiapkan PowerMTA untuk melakukan streaming acara ke akun SparkPost Anda, kemudian Anda akan dapat menggunakan yang berikut ini:
Firstly, install (or upgrade) to PowerMTA 5.0 r4 or later, following the instruksi penginstalan v5.0 biasa which are pretty straightforward. Then we’ll work through the following steps:
Konfigurasikan konektor PowerMTA to Sinyal SparkPost
Siapkan Pelacakan Keterlibatan dengan domain pelacakan khusus
Pilih aliran lalu lintas PowerMTA mana yang akan dilaporkan ke Sinyal
Menguji bahwa acara Anda mencapai Sinyal
Tinjau cara menggunakan nama-nama yang bermakna yang muncul dengan baik dalam pelaporan.
Kami juga akan membahas aspek pengaturan PowerPMTA spesifik lainnya yang digunakan dalam demo Sinyal kami:
Peristiwa FBL (Keluhan Spam) dan pantulan jarak jauh (di luar band)
Konfigurasi injeksi, termasuk DKIM
Konfigurasi FBL dan OOB
Pengaturan dan penamaan VirtualMTA (dan bagaimana hal ini muncul dalam laporan Sinyal SparkPost Anda)
Finally, there’s a “bonus feature” with code to ensure your campaign names are compatible with PowerMTA X-Job name conventions.
Configure PowerMTA connector
The Signals configuration is described in the 5.0 Bagian Panduan Pengguna 10.1. Here we’ll start with “Use Case #2”, which enables Signals for all traffic from this PowerMTA host, and enable SparkPost engagement tracking.
# # SparkPost Signals # <signals> api-kunci ##my ingest API key here## unggah-url https://api.sparkpost.com/api/v1/ingest/events log-verbose true ruang-bebas-minimal 1G engagement-tracking sparkpost # this turns on the open and click tracking in PowerMTA customer-id 123 # Your SparkPost account number here </signals> aktifkan-sinyal true
Berikut ini adalah fungsi setiap atribut:
api-kunci
Ini unik untuk akun SparkPost Anda, ini adalah nilai yang Anda dapatkan dari SparkPost sebelumnya.
unggah-url
Alamat ini harus sama dengan alamat layanan API SparkPost Anda, apakah itu AS atau UE. Untuk info lebih lanjut, lihat di sini. Nilai yang biasa digunakan adalah:
SparkPost (AS): https://api.sparkpost.com/api/v1/ingest/events
SparkPost EU: https://api.eu.sparkpost.com/api/v1/ingest/events
log-verbose
Arahan ini bersifat opsional dan jika diaktifkan, memberikan sedikit lebih banyak informasi dalam file pmta.log, yang dapat berguna selama penyiapan untuk mengonfirmasi bahwa semuanya bekerja dengan benar. Setiap menit, bahkan ketika tidak ada lalu lintas, Anda akan melihatnya:
2019-07-26 11:47:57 Sinyal: Ditemukan 0 file
Dengan lalu lintas, Anda akan melihat sesuatu seperti:
2019-07-26 11:50:57 Sinyal: Menemukan sp1-0000000000003FBD.json 2019-07-26 11:50:57 Sinyal: Berhasil mentransfer sp1-0000000000003FBD.json. 2019-07-26 11:50:57 Sinyal: Menemukan 1 file, berhasil mentransfer 1 file
ruang-bebas-minimal
Ini memberi tahu PowerMTA ambang batas ruang disk di mana ia harus mulai menghapus file peristiwa SparkPost JSON yang paling lama untuk menyediakan ruang bagi file baru ketika ruang disk hampir habis.
aktifkan-sinyal
This tells PowerMTA to upload to Signals, in this case globally for all traffic (more info di sini, untuk v5.0). You can be more selective about what traffic streams to upload if you wish.
You can also mark particular PowerMTA traffic to be reported as belonging to a SparkPost subaccount – this is another way to distinguish one particular traffic stream from another.
pelacakan-pelacakan-keterlibatan, id-pelanggan
PowerMTA’s Engagement Tracking solution defaults ke tracking domain for the SparkPost US-hosted service. You specify your SparkPost numeric customer ID; here’s petunjuk untuk menemukannya.
domain-pelacakan
Untuk akun SparkPost EU, tambahkan baris berikut:
tracking-domain pmta.eu.spgo.io # ini adalah titik akhir untuk SparkPost EU
Domain Pelacakan Khusus
Jika Anda lebih suka menggunakan domain pelacakan Anda sendiri (ini lebih baik dari sudut pandang keterkiriman), lakukan hal berikut:
Create tracking domain with your DNS provider by creating a CNAME record. This will usually be a subdomain of your top-level domain, e.g. track.mycompany.com .
track.mycompany.com CNAME pmta.spgo.io # jika Anda memiliki akun SparkPost US track.mycompany.com CNAME pmta.eu.spgo.io # jika Anda memiliki akun SparkPost EU
You can also use HTTPS tracking domains, although this is more involved (see SparkPost configuration steps here).
Register tracking domain in your SparkPost account, and memverifikasinya. Wait a few minutes before trying this, to allow your DNS changes to propagate through the Internet, depending on your DNS provider.
Konfigurasikan PowerMTA untuk menggunakan domain tersebut dan bukan default, dengan
tracking-domain yourdomain.com # Letakkan domain Anda sendiri di sini
Anda dapat memeriksa apakah email yang Anda kirimkan memiliki "piksel terbuka" yang ditambahkan dan tautan yang dibungkus, dengan melihat bagian dalam email (di Gmail, gunakan menu di kanan atas dan pilih "Tampilkan Asli").
You’ll notice the open pixels di beginning and end of the HTML in the email. Each HTML link is also changed to have REF pointing ke tracking domain.
Hanya itu yang Anda perlukan untuk membuat Sinyal SparkPost berfungsi dengan Pelacakan Keterlibatan bawaan PowerMTA.
Mencegah tautan tertentu di email html Anda dilacak
You can prevent PowerMTA from tracking specific links, by setting the custom attribute data-msys-clicktrack to “0” :
<a href="#" data-msys-clicktrack="0">Example</a>
PowerMTA tidak akan membungkus tautan. Ini juga akan menghapus atribut tersebut sebelum mengirimkan pesan ke penerima Anda.
Pilih aliran lalu lintas PowerMTA mana yang akan dilaporkan ke Sinyal
Anda dapat memilih Sinyal untuk diaktifkan:
Secara global (inilah yang kami gunakan dalam contoh di atas)
Untuk beberapa MTA Virtual dan tidak untuk yang lainnya
Untuk beberapa pool MTA Virtual dan bukan yang lain
Untuk alamat "Pengirim" atau "Dari" tertentu yang direlai oleh PowerMTA, yang dikombinasikan dengan pilihan kumpulan MTA Virtual / MTA Virtual
This configuration is very powerful and is illustrated through a series of contoh kasus penggunaan (v5.0) in the User Guide.
Menguji bahwa acara Anda mencapai Sinyal
Berikut ini adalah tampilan Sinyal SparkPost, yang terhubung ke PowerMTA. Anda dapat melihat bahwa skor kesehatan bervariasi.
Nama Kampanye tersedia sebagai aspek pelaporan, bersama dengan Subakun, Kumpulan IP, Penyedia Kotak Surat, dan Domain Pengirim.
Selain melihat log PowerMTA , Anda dapat memeriksa apakah data peristiwa mencapai SparkPost dengan melihat layar Integrasi Sinyal.
In your SparkPost Pencarian Acara screen, you should see events appear within a few minutes. These will include Injection and Delivery events, as well as Bounce, and potentially Out-of-Band Bounce and Spam Complaint events, if you’ve already configured PowerMTA to handle those for you.
If you have Engagement Tracking enabled, you will also see open , initial_open , and click events.
Menggunakan nama-nama yang bermakna dan muncul dengan baik dalam pelaporan
Setting up the PowerMTA VirtualMTA Pool names and Job names to be meaningful and human-readable is well worth doing. These show up directly in your SparkPost Signals facets and the Laporan ringkasan.
Seperti yang telah disebutkan sebelumnya, Anda tidak perlu membuat pool ini di akun SparkPost Anda. SparkPost mengambilnya dari konfigurasi PowerMTA Anda.
Berikut ini adalah bagaimana istilah-istilah konfigurasi PowerMTA diterjemahkan ke istilah-istilah SparkPost.
PowerMTA istilah Laporan / Sinyal SparkPost istilahRecipient Domain
(domain portion of “rcpt” field in Accounting file).Recipient DomainThe domain portion of the “Sender” or “From” header in the message relayed by PowerMTA.
(domain portion of “orig” in Accounting file).Sending DomainVirtualMTA (name)—VirtualMTA Pool (name)
(“vmtaPool” in accounting file)IP Pool (name)smtp-source-host a.b.c.d
(“dlvSourceIp” in accounting file)Sending IP a.b.c.dJob (name)
(“jobId” in accounting file)Campaign ID (name)—Template (name)“Subaccount” is not a native PowerMTA concept.
Namun, PowerMTA dapat menandai virtualMTA, kumpulan MTA virtual, atau domain Pengirim-dari-dan-Dari dengan ID subakun untuk tujuan pelaporan SparkPost.
ID Sub-Akun (nomor) FBL (peristiwa) Keluhan Spam (peristiwa) Pemantulan Jarak Jauh (peristiwa) Pemantulan di Luar Band (peristiwa)
Setting up at least one smtp-source-host address also enables SparkPost to correctly identify the sending IP address so that it shows up on Injection and Delivery events, as well as in the Laporan ringkasan view.
Job names are set in PowerMTA via a header in the injected message. As well as enabling individual job control (pause/resume etc) which is useful in itself, PowerMTA passes the names through to SparkPost Signals reporting as “campaign ID”. See User Guide v5.0 bagian 12.8 "Melacak kampanye di PowerMTA dengan JobID".
There are a few things to be aware of regarding job naming. While SparkPost (with JSON format, and JSON escaping) allows characters such as <SPACE> in campaign names, mail headers are more restrictive. Valid characters allowed in the X-Job header are:
A-Za-z0-9!#$%&'()*+,-./:;<=>?@[\]^_{|}~
In other words, disallowed characters include <SPACE>, double-quotes “ and backtick `. If you’re used to working with X-Job names, this won’t be surprising, and your campaign ID names will “just work” on SparkPost reporting. If like me, you learned SparkPost first, you might want a tool to ensure your X-Job values are safe; see the bonus feature di end of artikel ini.
Peristiwa FBL (Keluhan Spam) dan pantulan jarak jauh (di luar band)
PowerMTA dapat menerima dan memproses peristiwa FBL (dikenal di SparkPost sebagai peristiwa Keluhan Spam) dan pemantulan jarak jauh (dikenal di SparkPost sebagai pemantulan di luar jaringan, karena balasannya datang kembali beberapa saat setelahnya, bukan selama percakapan SMTP).
There are articles in the Port25 Dukung Forum on how to set up the Prosesor Pantulan and the Prosesor FBL. If you are an existing PowerMTA user, you probably already have these.
Berikut ini konfigurasi yang saya buat untuk demo, berdasarkan artikel-artikel ini dan berorientasi pada hosting PowerMTA di Amazon EC2.
Jika Anda sudah terbiasa dengan konfigurasi PowerMTA di area ini, Anda bisa melewatkan bagian ini, turun ke garis horizontal berikutnya.
Konfigurasi injeksi
Kita akan menggunakan port 587 untuk pesan yang diinjeksikan, yang akan datang melalui Internet publik dari hos lain. Kita perlu menghentikan pelaku kejahatan menemukan dan menyalahgunakan layanan ini, jadi kita menerapkan autentikasi nama pengguna/kata sandi dan TLS opsional, mirip dengan titik akhir injeksi SMTP SparkPost.
Kami ingin dapat mengirim pesan dari sumber yang diautentikasi dengan benar ke tujuan mana pun. Kami juga menginginkan pendengar terpisah pada port 25 untuk FBL dan respons pantulan jarak jauh yang tidak memerlukan autentikasi
# Alamat IP dan port yang digunakan untuk mendengarkan sambungan SMTP yang masuk # smtp-listener 0.0.0.0:587 smtp-listener 0.0.0.0:25
In the following <source> declarations, we’re using username/password authentication and optional TLS to defend against rogue message injection. We also set rate limits on connections making failed password attempts.
Penyiapan Anda mungkin berbeda; misalnya, jika Anda memiliki jaringan privat antara injektor dan PowerMTA, Anda tidak memerlukan autentikasi kata sandi.
# One source rule for all injection, internal or external. Enforce auth, except for bounces and FBLs # <source 0/0> log-connections false log-commands false # WARNING: verbose! just for dev log-data false # WARNING: even more verbose! smtp-service true # allow SMTP service smtp-max-auth-failure-rate 1/min allow-unencrypted-plain-auth false allow-starttls true rewrite-list mfrom </source> <source {auth}> always-allow-relaying yes # only if the auth succeeds default-virtual-mta default process-x-job true </source>
The <source {auth}> declaration (lihat di sini. v5.0) applies once authentication has passed. Here, it allows onward relaying, sets up the default virtual MTA group to use, and adds the X-Job header (which will be reported by SparkPost Signals as campaign_id).
Daftar tulis ulang memetakan pesan yang disuntikkan untuk menggunakan domain MAIL FROM tertentu (alias domain bounce atau Return-Path:).
# # Rewrite the MAIL FROM address to match the bounce domain # <rewrite-list mfrom> mail-from *@pmta.signalsdemo.trymsys.net *@bounces.pmta.signalsdemo.trymsys.net </rewrite-list>
Then we set up our Konfigurasi TLS and SMTP username / password, according to rekomendasi saat ini.
# # Secure the inbound service with username, password and TLS. SMT 2020-06-15 # smtp-server-tls-certificate /etc/pmta/pmtasignalsdemo.pem smtp-server-tls-allow-tlsv1 false smtp-server-tls-allow-tlsv1.1 false smtp-server-tls-allow-tlsv1.2 true smtp-server-tls-allow-tlsv1.3 true # # SMTP users (authenticated via SMTP AUTH) # <smtp-user SMTP_Injection> password ##PUT YOUR PASSWORD HERE## authentication-method password </smtp-user>
We can check that the (insecure, usang) TLS v1.0 is not accepted using my favorite SMTP test tool, swaks.
swaks --server pmta.signalsdemo.trymsys.net --port 587 --to test@trymsys.net --from any@sparkpost.com --tls --tls-protocol tlsv1
Kita lihat:
*** Startup TLS gagal (connect(): error: 00000000: lib(0): func(0): reason(0)) *** STARTTLS dicoba tetapi gagal
Likewise for -tls-protokol tlsv1_1.
Let’s also apply DKIM signing on our outgoing messages, as it’s good practice (I followed petunjuk ini to set up the key).
# # DKIM # domain-key mypmta, pmta.signalsdemo.trymsys.net, /etc/pmta/mypmta.pmta.signalsdemo.trymsys.net.pem
Konfigurasi FBL dan OOB
Now .. finally .. we declare which specific domains are open for remote bounce and FBL responses. We don’t want to relay those anywhere (to prevent serangan hamburan balik), just internally process those responses.
# # Enable Bounce and FBL processing on specific domains # relay-domain pmta.signalsdemo.trymsys.net relay-domain bounces.pmta.signalsdemo.trymsys.net relay-domain fbl.pmta.signalsdemo.trymsys.net <bounce-processor> deliver-unmatched-email no deliver-matched-email no <address-list> domain pmta.signalsdemo.trymsys.net domain bounces.pmta.signalsdemo.trymsys.net </address-list> </bounce-processor> <feedback-loop-processor> deliver-unmatched-email no deliver-matched-email no <address-list> domain fbl.pmta.signalsdemo.trymsys.net </address-list> </feedback-loop-processor>
You can see I set up two bounce domains, as I was playing around with using/not using the mfrom rewrite rule.
The FBL domain is usually then registered with external services such as Microsoft SNDS; see this article for more information. For this demo, the FBLs will be coming from the Wastafel Goyang, so no need to register.
Menguji pendengar SMTP
Penting untuk menguji bahwa pendengar SMTP Anda memerlukan otorisasi untuk semua tujuan umum, menolak semua pesan yang tidak secara khusus ditujukan ke domain FBL dan remote-bounce.
swaks --server pmta.signalsdemo.trymsys.net --port 25 --ke test@strange.pmta.signalsdemo.trymsys.net --dari any@sparkpost.com
Tanggapannya, seperti yang diharapkan, menunjukkan bahwa penyampaian ditolak:
550 5.7.1 relaying denied for recipient in "RCPT TO:<test@strange.pmta.signalsdemo.trymsys.net>
(Bagian akhir deskripsi penyiapan demo).
Pengaturan dan penamaan VirtualMTA
PowerMTA VirtualMTA (dan kumpulan VirtualMTA) adalah fitur yang kuat untuk mengelola aliran pesan, dan fitur pelaporan PowerMTA / SparkPost Signals bekerja paling baik dengan fitur-fitur ini aktif.
# # Route all outgoing traffic through this virtual mta / pool. # Declare the delivery IP address here, so that SparkPost signals ingest injection (aka "reception") events # will carry the correct sending_IP attribute # <virtual-mta mta1> smtp-source-host 172.31.25.101 pmta.signalsdemo.trymsys.net </virtual-mta> <virtual-mta-pool default> virtual-mta mta1 <domain *> max-smtp-out 20 # max. connections *per domain* bounce-after 4d12h # 4 days, 12 hours retry-after 10m # 10 minutes dkim-sign yes </domain> </virtual-mta-pool>
The virtual-mta-pool setting is reported in SparkPost as “IP Pool”, and is available as a SparkPost Signals reporting facet (the drop-down menu underneath the charts).
Laporan Ringkasan juga menunjukkan IP Pool sebagai aspek pelaporan "Group By".
As noted earlier in this article, setting up at least one smtp-source-host address also enables SparkPost to correctly identify the sending IP address, so that it shows up on Injection and Delivery events, and on the Summary Report:
That’s all you need to get a basic integration working between PowerMTA and SparkPost Signals. You’ll find the contoh file konfigurasi lengkap di sini.
Sebelum Anda pergi, inilah fitur bonus yang saya sebutkan.
Fitur bonus: Pemeriksaan/penyaringan nama X-Job
To ensure any character string is safe for use as a PowerMTA X-Job name, here’s a simple Python function to map any unsafe characters to an underscore “_”
import re def pmtaSafeJobID(s): """ :param s: str :return: str Map an arbitrary campaign ID string into allowed chars for PMTA X-Job header. See https://download.port25.com/files/UsersGuide-5.0.html#tracking-a-campaign-in-powermta-with-a-jobid Specifically disallow <sp> " ` but allow through most other chars. """ # Note have to escape ' - [ ] and double-escape \ - see https://docs.python.org/3/library/re.html disallowedChars = '[^A-Za-z0-9!#$%&\'()*+,\-./:;<=>?@\[\\\\\]^_{|}~]' return re.sub(disallowedChars, '_', s)
This uses Ekspresi reguler Python in a specific way. It declares the set of disallowed characters using the “set complement” operator ^ rather than list all allowed chars. That means we catch (and make safe) characters beyond the usual 7-bit set. We can show that using this test fragment:
s='' for i in range(32, 256): s += chr(i) print(pmtaSafeJobID(s))
Memberi
_!_#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^__abcdefghijkl mnopqrstuvwxyz{|}~___________________________________________________________ ______________________________________________________________________
You can see that <SPACE>, double-quotes “, and backtick `, as well as all characters beyond ~ are mapped to underscore.