文档
-
入门
入门
你应该知道的东西
BeInBox is a SMTP relay. The service is simple to implement.
我们比其它的服务商提供更清晰的发送数据报告.
我们追踪您发送的电子邮件,如果出现问题,我们会第一时间为您解决问题.
我们主要针对大型电子商务性质的公司.
我们坚决杜绝垃圾邮件,这些邮件会被我们的监控工具直接处理. 我们每封电子邮件的最大限度是10Mb.
我们的服务器支持持久连接.
您可以在电子邮件头部添加任何以X-***格式开头的字符串作为标记.
我们会对您的电子邮件进行编码处理,用来处理各个国家的语言. -
Tags
Tags
你应该知道的东西
You can add “Tags” to your emails, this will allow you to segment your sending, as for exemple separate an confirmation email from a registering email, or even men from women recipient…
如果你想同时使用多个标签,你只需要用逗号分隔它们.
我们提供两种方法:
1. 将内容添加到电子邮件中(请注意邮件主题和内容不能超过245个字符): 添加一个[标签:xxxxxxx ]到你的邮件主题里,例如:欢迎[标签:登录,男]
2. 在电子邮件中添加一个X-Tag: 在你的电子邮件中添加一个头部标签:X-Tag:登录,男
我们的系统将检测您在电子邮件中留的标签,之后您可以在日志中查询到它们: webhooks、日志和数据分析. -
SMTP配置
SMTP(简单邮件传输协议)配置
你应该知道的东西
BeInBox is a SMTP relay. To send emails, you only need to point to our globally secure SMTP servers.
服务器: smtp.BeInBox.com
端口: 25, 2525, 587
SSL端口: 465
我们支持ESMTP并使用TLS加密方式. 您可以选择使用ESMTP并用TLS加密方式连接我们的端口25.
就是这么简单!
如果您想使用我们的API来发送电子邮件,您可以参考我们的示例代码 (https://github.com/BeInBox/smtp-relay-snippets)ASP.net
使用API
如果您使用的是.NET: .Net Connector.
SMTP
您也可以在这里找到已经编译的版本: .Net compiled Connector下面是一段代码示例,您可以直接用来发送电子邮件.
MailMessage message = new MailMessage();
message.From = new MailAddress("your_email@example.com");
message.To.Add(new MailAddress("recipient1@example.com"));
message.To.Add(new MailAddress("recipient2@example.com"));
message.To.Add(new MailAddress("recipient3@example.com"));
message.Subject = "Subject goes here";
message.Body = "The message goes here";
SmtpClient client = new SmtpClient();
client.Send(message);
System.Net.Mail 从« web.config »文件中读取SMTP配置. 下面是配置它的一种示例:
<system.net>
<mailSettings>
<smtp from="your_email@example.com">
<network host="smtp.BeInBox.com" port="587" userName="YourBeInBoxUsername"
password="YourBeInBoxPassword" defaultCredentials="false" />
</smtp>
</mailSettings>
</system.net> -
JAVA
SMTP配置
Java
使用API
直接下载一个简单版的JAVA代码示例: Java Connector.
或者使用下一示例 .Net Compiled Connector.
以下是示例代码.
/*
* This class is just here for demo purposes.
*/
package net.mxm.connector.test;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.mxm.connector.ArrayEmail;
import net.mxm.connector.CampaignParameters;
import net.mxm.connector.Content;
import net.mxm.connector.Email;
import net.mxm.connector.MxmConnect;
import net.mxm.connector.MxmConnectConfigurationException;
import net.mxm.connector.MxmConnectException;
/**
* @author nico toper
* @date 2010-10-20
*/
public class MxmTest extends Thread {
public MxmConnect mxm = null;
public int res[] = new int[20];
public MxmTest() throws MxmConnectException {
//mxm = new MxmConnect();
for (int i = 0; i < res.length; i++) {
res[i] = 0;
}
}
@Override
public void run() {
for (int i = 0; i < 2000; i++) {
try {
try {
long fStart = System.currentTimeMillis();
this.sendEmail();
//System.out.println("Time for this mail: " + ( System.currentTimeMillis() - fStart) );
} catch (MxmConnectException ex) {
Logger.getLogger(MxmTest.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (MxmConnectConfigurationException ex) {
Logger.getLogger(MxmTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
void testOthers() throws MxmConnectException, MxmConnectConfigurationException {
MxmConnect mxm2 = new MxmConnect("", "");
// mxm2.createTag("test");
// mxm2.createTag("test2");
String[] t = mxm2.listAllTags();
for (int i = 0; i < t.length; i++) {
System.out.println(t[i]);
}
// System.out.println(mxm2.deleteTag("test2"));
}
private String makeRandom() {
Double r = new Double(Math.random() * 1000000);
return r.toString(r);
}
protected void sendEmail() throws MxmConnectConfigurationException, MxmConnectException {
MxmConnect mxm2 = new MxmConnect("", "");
//MxmConnect mxm2 = mxm ;
// mxm2.setFastDelivery(true);
CampaignParameters cp = new CampaignParameters();
cp.setMailFrom("test@test.com");
cp.setMailFromFriendly("FriendlyName");
cp.setReplyTo(this.makeRandom());
cp.setReplyToFiltered(false);
String tags[] = { "test" };
cp.setTags(tags);
Content c = new Content();
//c.setSubject(this.makeRandom());
//c.setText(this.makeRandom());
c.setSubject("Your Subject");
c.setText("test");
StringBuffer sb = new StringBuffer();
String r = this.makeRandom();
for (int i = 0; i < 2000; i++) {
sb.append(r);
}
c.setHtml(sb.toString());
Email e = new Email();
e.setEmail("test@test.com");
ArrayEmail ae = new ArrayEmail();
ae.addEmail(e);
String host = mxm2.getHost();
System.out.println(host);
System.out.println(mxm2.sendCampaign(c, cp, ae));
//System.gc();
}
//This is the entry point for test.
public static void main(String[] args) throws MxmConnectException, MxmConnectConfigurationException {
//HeapMonitor h = new HeapMonitor();
//h.start();
for (int i = 0; i < 1; i++) {
MxmTest mxm = new MxmTest();
for (int j = 0; j < 100000; j++) {
mxm.sendEmail();
System.out.println("ok");
for (int x = 0; x < mxm.res.length; x++) {
System.out.println(x + ": " + mxm.res[x]);
}
}
}
}
以下是示例代码:
import java.io.*;
import java.net.InetAddress;
import java.util.Properties;
import java.util.Date;
import javax.mail.*;
import javax.mail.internet.*;
import com.sun.mail.smtp.*;
public class Distribution {
public static void main(String args[]) throws Exception {
Properties props = System.getProperties();
props.put("mail.smtps.host","smtp.BeInBox.com");
props.put("mail.smtps.auth","true");
Session session = Session.getInstance(props, null);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("your_email@example.com"));
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse("Recipient_address@example.com", false));
msg.setSubject("Your subject here "+System.currentTimeMillis());
msg.setText("Your content here");
msg.setHeader("X-Mailer", "Header");
msg.setSentDate(new Date());
SMTPTransport t = (SMTPTransport)session.getTransport("smtps");
t.connect("smtp.BeInBox.com", "YourBeInBoxUsername", "YourBeInBoxPassword");
t.sendMessage(msg, msg.getAllRecipients());
System.out.println("Response: " + t.getLastServerResponse());
t.close();
}
}
-
PHP
SMTP配置
PHP
使用API
直接下载一个简单版的PHP代码示例: PHP Connector.
以下是示例代码.
$content = array('subject'=> 'My subject', 'html'=> 'my html' , 'text' =>'my test');
$param = array('tag'=>array('invoice1'), 'mailfrom'=> 'ntoper@BeInBox.com', 'mailfrom_friendly'=> 'Nicolas Toper', 'replyto'=>'ntoper@BeInBox.com', 'replyto_filtered'=> 'true');
$emails[0] = array('email'=>'happy@customer.com', 'field1'=> 'test');
try {
echo $j;
print_r($mxm->sendCampaign($content, $param, $emails));
} catch (MxmException $e) {
echo $e->getMessage();
}
-
Python
SMTP配置
Python
使用API
直接下载一个简单版的Python代码示例: Python Connector.
SMTP
以下是示例代码.
import smtplib
#your BeInBox's credentials
BeInBox_user = 'YOUR BeInBox USERNAME'
BeInBox_password = 'YOUR BeInBox PASSWORD'
sender = "YOUR NAME "
recipients = ['RECIPIENT EMAIL']
subject = "My subject"content = """My email message"""
message = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n%s" % (sender, ", ".join(recipients), subject, content))
try:
server = smtplib.SMTP("smtp.BeInBox.com", 587)
server.ehlo()
server.starttls()
server.ehlo
server.login(BeInBox_user, BeInBox_password)
server.sendmail(sender, recipients, message)
print "Successfully sent email"
except SMTPException:
print "Error: unable to send email" -
Ruby
-
SMTP
SMTP配置
SMTP
以下是示例代码.
#Put in a file like config/initializers/BeInBox.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.BeInBox.com",
:port => 587,
:authentication => :plain,
:user_name => "YOUR_BeInBox_USERNAME",
:password => "YOUR_BeInBox_PASSWORD",
:enable_starttls_auto => false
}
ActionMailer::Base.delivery_method = :smtp -
DNS设置
DNS设置
DKIM设置
强烈建议设置您的DKIM以提高您的电子邮件的交付能力. 您可以获取更多的信息. 此操作可以提高互联网服务供应商对您电子邮件的公信度.
假设您使用的域名是example.com.
1) 首先,添加以下名称和值到CNAME. IP地址、域名或者服务器名字: BeInBox2._domainkey.example.com
值: dkim.BeInBox.com.
请注意,有时您的域名可能会有默认值. 在这种情况下,您将不得不在Address中删除example.com字段.
如果您的DNS客户端不支持CNAME中带有下划线,则需要直接添加在TXT记录中:
IP地址、域名或者服务器名字: BeInBox2._domainkey.example.com
Value: k=rsa\; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCvEpIr9ILg7iXsdMlMst5sCK+MDc4GQDaZDmgLLHHVNn952Jh4zmB1Qp+fBSUzVfcU/qW4hicOMJKRe0bo8nIB/Gvh3CtJuyAFizXCUjDtn2V4t5rg2OEpVkEXHkwUoW43Z5753Q62flW2wb3zuEqoO5fWLUt4rcIqatE+O8zmSwIDAQAB
2) In your BeInBox account, go to 'Account -> Mail Settings' and find the 'Signed-by Domain' line.
电子邮件提供商将使用对应的值检查相应的DKIM记录. 例如,如果在步骤1中使用了example.com,则需要在此字段中输入example.com.
注意:Hotmail的DKIM验证过程需要From地址域与DKIM签名域相同. 因此,如果您的签名域是example.com,您的From地址应该为类似于hello@example.com.
如果您还没有设置SPF,我们建议您立即去设置.
3) 测试您的设置
一旦您设置了DKIM,就可以开始测试它了 在这里. Use 'BeInBox2' as Selector and your own domain name as Domain Name (Wait 4 hours for DNS propagation though.) -
DKIM设置
DNS设置
DKIM设置
强烈建议设置您的DKIM以提高您的电子邮件的交付能力. 您可以获取更多的信息. 此操作可以提高互联网服务供应商对您电子邮件的公信度.
假设您使用的域名是example.com.
1) 首先,添加以下名称和值到CNAME. IP地址、域名或者服务器名字: BeInBox2._domainkey.example.com
值: DKIM.BeInBox.com
请注意,有时您的域名可能会有默认值. 在这种情况下,您将不得不在Address中删除example.com字段.
如果您的DNS客户端不支持CNAME中带有下划线,则需要直接添加在TXT记录中:
IP地址、域名或者服务器名字: BeInBox2._domainkey.example.com
Value: k=rsa\; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCvEpIr9ILg7iXsdMlMst5sCK+MDc4GQDaZDmgLLHHVNn952Jh4zmB1Qp+fBSUzVfcU/qW4hicOMJKRe0bo8nIB/Gvh3CtJuyAFizXCUjDtn2V4t5rg2OEpVkEXHkwUoW43Z5753Q62flW2wb3zuEqoO5fWLUt4rcIqatE+O8zmSwIDAQAB
2) In your BeInBox account, go to 'Account -> Mail Settings' and find the 'Signed-by Domain' line.
电子邮件提供商将使用对应的值检查相应的DKIM记录. 例如,如果在步骤1中使用了example.com,则需要在此字段中输入example.com.
注意:Hotmail的DKIM验证过程需要From地址域与DKIM签名域相同. 因此,如果您的签名域是example.com,您的From地址应该为类似于hello@example.com.
如果您还没有设置SPF,我们建议您立即去设置.
3) 测试您的设置
一旦您设置了DKIM,就可以开始测试它了 在这里. Use 'BeInBox2' as Selector and your own domain name as Domain Name (Wait 4 hours for DNS propagation though.) -
SPF设置
DNS设置
SPF设置
设置一个安全的SPF可以提高您的电子邮件的交付能力. 而且该设置只需要两步.
假设您使用的域名是example.com.
1) 在您的域名中添加以下的TXT记录: IP地址、域名或者服务器名字: example.com
TXT值: v=spf1 mx include:messaging-master.com ~all
如果您的域名中已经设置了SPF,那么只需在您现有的设置中添加 include:messaging-master.com 即可.
2) In your BeInBox account, go to 'Account -> Mail Settings' and find the 'On Behalf of Addresses' line.
在您刚刚更新的域名中设置一个默认的电子邮件发送地址,例如 noreply@example.com. 注意:您可以在这个域名中设置多个电子邮件发送地址,但是您只能在每个域添加一个优先地址. 可以使用逗号将每个地址分隔开.
注意,这与您的邮件-从:或从:地址不相同,而且它不影响您的邮件-从:或从:地址在任何方式。它将仅供电子邮件提供商使用,以检查是否有适当的spf txt记录.
3) 测试您的设置
一旦你建立了你的SPF,你可以测试你的域名 在这里. 当点击“获取SPF记录”时,您应该在结果中看到“messaging-master.com” (等待4个小时) -
发送电子邮件
发送电子邮件
使用Python:
import smtplib
server = smtplib.SMTP('smtp.BeInBox.com')
server.login(‘MYLOGIN’, MyPass) server.sendmail(‘support@BeInBox.com’, ‘ntoper@gmail.com’, ‘Hello there’) -
按比例发送给我们
发送电子邮件
按比例发送给我们
BeInBox is able to receive more than 3 million emails per hour. We can increase or decrease this capacity as quickly as necessary as our system is fully distributed and spread out all around the globe. We are able to send your emails within two minutes provided your reputation with ISP is good enough.
如果你想发送规模和速度,这里有一些提示:
SMTP非常详细,速度很慢. 这是因为协议需要在客户端和服务器之间进行大量的往返. 为了加快速度,显而易见的工作解决方案是使用多线程和多处理.
Ideally try to hit a different server each time (by resolving again and again 'smtp.BeInBox.com'; be careful- some frameworks will cache it and will resolve to the same servers).
在可能的情况下重用连接以避免身份验证往返.
有时准备发送电子邮件(例如,生成内容、编码)可能需要一段有意义的时间. 它有助于在发送之前提前做好准备.
Feel free to contact us on support@BeInBox.com if you need any help. -
统计和大数据
统计和大数据
我们收集您可以在任何时候访问您的交付的统计数据:
分析 https://account.BeInBox.com/analytics/delivery 为您呈现统计信息的汇总视图. 这使您可以查明和解决任何问题.
日志 https://account.BeInBox.com/logs/index are a detailed view of your deliveries. If you pass us a X-uid or some tags, we will put them here. We keep data for 15 days.
Webhooks API与日志相同,只是我们将所有这些数据都推送到推送HTTP请求中. https://account.BeInBox.com/delivery/event_api
这是我们跟踪他们定义的事件的完整列表.
我们跟踪任何事件:
接收者 您的电子邮件
网络供应商: 收件人的域名. 例如,我们的公司域名mxmtech为Gmail.
交付时间: 我们为每封收到的邮件添加时间戳.
主机名: 传送电子邮件的机器的名称.
X-UID: 这是您在电子邮件中作为X-UID标头传递的任何字符串(<755个字符).
标签: Passed in X-Tags (or in [Tags:…] in the subjet. It’s a comma separated lists.
附加字符串: 这是我们把额外的信息,如SMTP错误代码和消息.
我们跟踪的事件:
已打开: 我们记录所有的原子打开,只有当用户显示图像. 通常我们的记录比我们的竞争更少,因为我们的系统被配置为在整个查询完成时记录打开.
垃圾邮件报告: 当用户将您的电子邮件标记为垃圾邮件时会发生,在这种情况下,我们将其添加到我们的抑制数据库. 当Outlook,Yahoo(如果您要求我们验证您的DKIM),AOL和所有由返回路径运行的FBL.
被反弹: 当电子邮件反弹时,我们会尝试重新发送长达12小时. 所有的错误代码都会在SMTP服务器的回答中记录下来. SMTP错误代码是4XX,通常表示暂时错误.
永久失败: 当我们知道SMTP代码是5XX格式时就会发生. 我们不会在这一步标记地址为无效地址.
已发送: 我们已经发送电子邮件到SMTP服务器.
被过滤: 过滤电子邮件是在我们的删除列表(todo put链接),我们筛选出来. 电子邮件没有发送.
被阻止: The SMTP server rejected the email. Usually this happens because the IP is blacklisted or because the content is seen as spam. When you see this event, you can contact us on support@BeInBox.com for some additional explanations.#Email landed in spambox.
已接收: 此事件意味着我们收到了您发送的请求.
错误: 我们无法发送您的电子邮件. 因为我们喜欢透明度,所以你会看到Python堆栈跟踪. 如果你看到这些,请联系我们,因为这是非常罕见的.
被点击: 用户点击您的链接. 额外的字符串将包含点击的链接.
DT_ATOMIC_OPEN = 24 => 首次被打开
#Isp accepted with response code
DT_ISP_ACCEPTED = 29 => 网络供应商接受确认(附信息)
#Isp deferred code
DT_ISP_DEFERRED = 30 => 电子邮件被网络供应商推迟
#Temp new arrival replace code 12 using on production
DT_ARRIVED = 31 => BeInBox input confirmation -
删除列表
删除列表
当用户将您的电子邮件报告为垃圾邮件,取消订阅或电子邮件反弹太多时,我们会将其添加到我们的删除列表. 这样,你不需要做任何事情. 下一封电子邮件将在您的分析中被视为已过滤.
以下是我们将在该列表中添加地址的具体情况的描述:
用户将您的邮件标记为垃圾邮件: 我们收到了网络供应商的通知.
我们在我们的删除列表中标记它.
这些用户被自动过滤.
用户取消订阅: 当用户退订您的服务时,他会自动添加到该数据库.
电子邮件被列入黑名单: 在收到我们收到的投诉或您添加的电子邮件之后,我们可以将您的电子邮件列入黑名单.
电子邮件被拒收: 当电子邮件被拒收时,我们将其添加到共享的退回地址池. 这些地址将保留6个月,然后删除. 没有成功交付,我们等待连续三周的继续发送尝试. 这部分是高于现有技术. 我们进行了一些研究,发现它为我们的客户提供了更好的服务.
默认情况下,标签是基于每个帐户启用的. 如果您使用标签,则可以激活一个选项,以每个标签为基础而不是以每个帐户为基础来过滤这些电子邮件.
您可以在这里查看给定地址的状态 https://account.BeInBox.com/delivery/filters, 你可以删除/添加地址. -
交付能力
交付能力
交付能力是确保您的电子邮件到达目标收件箱的能力. 我们监控您的邮件交付过程,将部分内容复制到我们的一些测试地址(这被称为种子地址;确切的算法是我们秘密的一部分). 当我们发现特定的流正在登陆垃圾邮件箱时,我们通常会与您联系(有时如果我们认为事情会自行恢复正常,如果有疑问,请与我们联系;我们喜欢与客户互动).
通常,垃圾邮件有三个来源:
IP声誉: 尽管近来这种情况变得越来越不重要,但这种情况仍然存在. 当一个特定的IP发送垃圾邮件时,一些SMTP服务器将在IP级别阻止垃圾邮件源. 阻止列表是一样的. Usually we are notified of such an issue, but you can get in touch with us on support@BeInBox.com. 我们有我们的工具来检测块并采取行动. 如果您在专用群集上,请告诉我们您是否需要访问.
内容: 出于某些原因,您的电子邮件将触发垃圾邮件过滤器. 例如,如果您是从尼日利亚发送伟哥收据的合法药房,您的电子邮件将很难发送.
垃圾邮件报告: 当太多的用户(> 0.1%)将您的电子邮件标记为垃圾邮件时,您的邮件将会被标记为垃圾邮件. 通常,垃圾邮件过滤器会使用您交付的某些元素,并将其添加到阻止列表中. -
Event API
Event API
Overview
The Event API allows users to setup web services to receive event notifications about their emails and their recipients from BeInBox.
You can enable the Event API by specifying a target URL in the ‘Event API’ section under the ‘Mail Settings’ tab. In the same section, you will be able to choose which categories you wish to enable (see the categories below).
A HTTP POST will be issued to the URL you’ve specified at a fixed interval (e.g. 5 minutes) with all the events we received in the meantime. The POST request payload describes the collection of events using the Webhooks model, and consists of a UTF8-encoded JSON array of JSON objects (events) in the following format:
[{
"category": "hard_bounce",
"date": "2011-09-02T14:39:53",
"recipient": "recipient1@example.org",
"mx": "example.com",
"tags": ["default", "tag1"],
"uid": "CC27F483098347ECB693EC7A1CAF45E9"
},
{
"category": "blocked",
"date": "2011-09-02T14:55:53",
"recipient": "recipient2@example.org",
"mx": "example.com",
"tags": ["default", "tag2"],
"uid": "A5DA637119D041BABAE316D3E908FF0A"
},
... ]
While we will make a best effort to promptly deliver all Webhooks events, messages may not arrive in order of commit. If we fail to reach the specified URL, we will retry several times over a 7-days period. This allows your services to be down for short maintenance windows and still receive all messages. Web services should respond to the POST request with a 2XX response code to indicate successful delivery. Redirects (3XX response codes) are not followed, and no further delivery attempts will be made. Server errors (5xx response codes) are treated as failures and will be retried. All other response codes will be ignored.
Event API format
The payload’s event JSON object contains the following items:
The list of event categories is:
- open: When the recipient opens an email. Counted only for HTML emails and image-view-enabled recipients.
- click: When the recipient clicks a link in your email.
- unsubscribed: When the recipient unsubscribed from your email traffic.
- bounce: When we receive a bounce (either soft or hard) for an email. Future emails to that address *will be* delivered.
- hard_bounce: Deprecated in favour of ‘bounce’.
- soft_bounce: Deprecated in favour of ‘bounce’.
- blocked: When we receive a notification from a recipient’s servers that an email of yours has been blocked for spam or content reasons. Future emails to that address *will be* delivered.
- spam_report: When a user has reported an email of yours as Spam to an ISP within our Feedback Loop. Future emails to that address will *not* be delivered.
- filtered: When we filter an email of yours and it is not sent out (due to various reasons, for example; we have received too many permanent failures for the address or it has been unsubscribed or it has sent a spam report etc).
- error: When there is an email’s structure or other internal error.
- new_failed_address: When we filter an email address after receiving too many permanent failures for it. Future emails to that address will *not* be delivered.
- filtered_address: Deprecated in favour of ‘new_failed_address’
- blacklisted_address: When a user blacklists an address from here. Future emails to that address will *not* be delivered.
- unblacklisted_address: When a user removes an address from their blacklist. Future emails to that address *will be* delivered.
- freed_address: When we remove an email address during our periodic failed addresses’ assessment and cleanup procedure (failed addresses are those we have received too many permanent failures for). Future emails to that address *will be* delivered.
Note 2: All deprecated events will stop being sent by 1st March 2013. Until then, we will send both the old (deprecated) and the new events.
Errors: If there are errors decoding your tags or other you have returned you will recieve the following error in the form of JSON:
[{
"error": "Invalid Character",
},
... ]
Authentication
You will find your unique Webhooks ‘secret key’, in the ‘Event API’ section under the ‘Mail Settings’ tab. This key is used to seed the HMAC-SHA256 algorithm. Each POST request contains header called X-BeInBox-Webhooks-Signature used to authenticate the payload. This header’s value is a 64-character hexadecimal string. To verify the Webhook request is originating from BeInBox you encode the payload with the HMAC-SHA256 algorithm (using your Webhooks ‘secret key’ as a key and SHA256 digest mode) and compare the resulting hexdigest to the X-BeInBox-Webhooks-Signature header’s value (signature).
Authentication in Python
import hmac, hashlib
def is_authenticated(your_webhooks_key, your_request_json_payload, x_BeInBox_webhooks_signature):
my_signature = hmac.new(key=your_webhooks_key, msg=your_request_json_payload, digestmod=hashlib.sha256).hexdigest()
return x_BeInBox_webhooks_signature == my_signature
Authentication in PHP:
function is_authenticated($your_webhooks_key, $your_request_json_payload, $x_BeInBox_webhooks_signature) {
$my_signature = hash_hmac("sha256", $your_request_json_payload, $your_webhooks_key);
return $x_BeInBox_webhooks_signature == $my_signature;
}
Example in PHP:
$our_webhooks_key = "xxxxxxxxxxxxxxx";
$BeInBox_signature = $_SERVER["HTTP_X_BeInBox_WEBHOOKS_SIGNATURE"];
$json_payload = file_get_contents('php://input');
# Check if payload is valid
if($BeInBox_signature != hash_hmac("sha256", $json_payload, $our_webhooks_key)) {
throw exception("Invalid payload according to our webhooks key");
}
$events = json_decode($json_payload);
foreach($events as $event) {
switch($event["category"]) {
case "open":
event_open($event);
break;
case "click":
event_click($event);
break;
case "unsubscribed": event_unsubscribe($event);
break;
case "hard_bounce":
event_hard_bounce($event);
break;
case "soft_bounce":
event_soft_bounce($event);
break;
case "blocked":
event_blocked($event);
break;
case "spam_report":
event_spam_report($event);
break;
case "filtered":
event_filtered($event);
break;
case "error":
event_error($event);
break;
default:
throw exception("Invalid category");
}
} - open: When the recipient opens an email. Counted only for HTML emails and image-view-enabled recipients.