从原始身体发送邮件进行测试 [英] Send Mail from raw body for testing purposes

查看:151
本文介绍了从原始身体发送邮件进行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个需要从电子邮件服务器检索任意电子邮件的PHP应用程序。然后,消息被完全解析并存储在数据库中。



当然,我必须做很多测试,因为这个任务并不是那么简单阳光下的邮件格式。因此,我开始从某些客户端收集不同内容的电子邮件。



我想要一个脚本,以便我可以将这些电子邮件自动发送到我的应用程序来测试邮件处理。



因此,我需要一种发送原始电子邮件的方法,以便结构与相应客户端的结构完全相同。我有电子邮件存储为.eml文件。



有人知道如何通过提供原始身体发送电子邮件?



编辑:
更具体地说:我正在寻找一种通过使用其源代码发送多部分电子邮件的方法。例如,我希望能够使用这样的东西(一个带有纯HTML和HTML部分的电子邮件,HTML部分有一个内联附件)。

  --Apple-Mail-159-396126150 
Content-Transfer-Encoding:quoted-printable
Content-Type:text / plain;

纯文本电子邮件!

- = 20

= 20
= 20

--Apple-Mail-159-396126150
内容 - 类型:multipart / related;
type =text / html;
boundary = Apple-Mail-160-396126150


--Apple-Mail-160-396126150
内容转移编码:quoted-printable
内容类型:text / html;
charset = iso-8859-1

< html>< head>
< title> Daisies< / title> = 20
< / head>< body style = 3Dbackground-attachment:initial; background-origin:=
initial; image:= $​​ b $ b url(cid:4BFF075A-09D1-4118-9AE5-2DA8295BDF33 / bg_pattern.jpg); =
background-position:50%0px;>

[ - snip - html电子邮件内容]


< / body>< / html> =

- Apple-Mail-160-396126150
Content-Transfer-Encoding:base64
Content-Disposition:inline;
filename = bg_pattern.jpg
内容类型:image / jpg;
x-apple-mail-type =文具;
name =bg_pattern.jpg
Content-Id:< 4BFF075A-09D1-4118-9AE5-2DA8295BDF33 / tbg.jpg>

/ 9j / 4AAQSkZJRgABAgAAZABkAAD / 7AARRHVja3kAAQAEAAAASAAA / + IFOElDQ19QUk9GSUxFAAEB
[ - snip - 图像内容]
nU4IGsoTr47IczxmCMvPypi6XZOWKYz / AB42mcaD / 9k =

- -Mail-159-396126150--


解决方案

快速shell脚本处理一个目录,并在你想要的时候调用它在 ls / mydir / do cat I | awk .. | sendmail -options



http://www.manpagez.com/man/1/awk/



您还可以使用脚本与邮件服务器通话发送 emls 与模板身体..


I am developing a PHP application that needs to retrieve arbitrary emails from an email server. Then, the message is completely parsed and stored in a database.

Of course, I have to do a lot of tests as this task is not really trivial with all that different mail formats under the sun. Therefore I started to "collect" emails from certain clients and with different contents.

I would like to have a script so that I can send out those emails automatically to my application to test the mail handling.

Therefore, I need a way to send the raw emails - so that the structure is exactly the same as they would come from the respective client. I have the emails stored as .eml files.

Does somebody know how to send emails by supplying the raw body?

Edit: To be more specific: I am searching for a way to send out multipart emails by using their source code. For example I would like to be able to use something like that (an email with plain and HTML part, HTML part has one inline attachment).

 --Apple-Mail-159-396126150
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;

The plain text email!

--=20    

=20
=20

--Apple-Mail-159-396126150
Content-Type: multipart/related;
    type="text/html";
    boundary=Apple-Mail-160-396126150


--Apple-Mail-160-396126150
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
    charset=iso-8859-1

<html><head>
    <title>Daisies</title>=20
</head><body style=3D"background-attachment: initial; background-origin: =
initial; background-image: =
url(cid:4BFF075A-09D1-4118-9AE5-2DA8295BDF33/bg_pattern.jpg); =
background-position: 50% 0px; ">

[ - snip - the html email content ]


</body></html>=

--Apple-Mail-160-396126150
Content-Transfer-Encoding: base64
Content-Disposition: inline;
    filename=bg_pattern.jpg
Content-Type: image/jpg;
    x-apple-mail-type=stationery;
    name="bg_pattern.jpg"
Content-Id: <4BFF075A-09D1-4118-9AE5-2DA8295BDF33/tbg.jpg>

/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAASAAA/+IFOElDQ19QUk9GSUxFAAEB
[ - snip - the image content ]
nU4IGsoTr47IczxmCMvPypi6XZOWKYz/AB42mcaD/9k=

--Apple-Mail-159-396126150--

解决方案

Just make a quick shell script which processes a directory and call it when you want e.g. using at crontab etc

for I in ls /mydir/ do cat I | awk .. | sendmail -options

http://www.manpagez.com/man/1/awk/

You could also just talk to the mail server using the script to send the emls with a templated body..

这篇关于从原始身体发送邮件进行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆