3

我正在尝试从我的应用程序发送电子邮件。我按照以下方式在自定义 ActivityProviderMessage 中格式化电子邮件:

return [NSString stringWithFormat:@"<html><body>This is my html email body and
here is a very long url link: <a href=\"%@\">Long url link</a></body></html>", _url];

问题在于,当我收到电子邮件并查看源代码时,该 url 被搞砸了,因为它已被放在多行中,并且在每行末尾插入了很多 =。该 URL 实际上是一个 Base64 编码的图像,将其粘贴到 safari 中时可以很好地显示图像。

这是一个小图像 url 的示例,将其粘贴到 safari 中,您将看到图像:

数据:图像/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+MTFGOTk4RENGNzIxMUUyOUY1REQxQkQ4NDFFMzEwMCI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOjExMUY5OThBQ0Y3MjExRTI5RjVERDFCRDg0MUUzMTAwIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjExMUY5OThCQ0Y3MjExRTI5RjVERDFCRDg0MUUzMTAwIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+R9i41AAAAedJREFUeNq8l81Kw0AQx9NQPHupoAhttVqw2oqePPkK3n0DT55sK1ZBq1a9+CIefADPnvyoVfEzVVAQwZMoFEGchQ2Mf3aTTdp04E93N7P5JbszO2kssfZjRWAOKU0aJL2qHOwIocJeSCPdAN8yqGt3pGyU4AZpVHPthjQUBficNO7j80ga6CT4ilQw9BWBlhCNeJvQJ1Iy4Jx3Up/dZvRy6FuAuWdhwU2I3gqpX/762YPI7zBgMTEF0KpsV33gDTev7RCBNMz6RQa1GLyomHtByoeJ6jppjPXLpF3DudcY+abgf09LViLVNL4rpB3I3xw6maTTPSnD+kukPQ/oBqRbRuUYN4jeFLypDroM0CYek6ZL7QAUl9CCINtk/WcvqBfYgTxdhRsjtAaBlPLbP9ugtOES4p7WIPJzJtFq+5Q2sWTbmrkleKBL0qRpbiIYS1tS5itaGR5IFPuJICcRBy9ofLbgGKzIMR692aDnbhwCyLUp0gHb63XSL2sbpYyXxeRXZg+pxcc1eYy1OB22ptqKvZ1nbXHjY02FCg3lS32iKOizshLNKCI/3+73kgD3wpiIziOPYlGwOmBiqb9hbF/h90Fa7BTUfeOWx/U50mEU/3FU1WmadGpFbAL8KY9J8ftldcn+BBgAl0Jc3zM1awwAAAAASUVORK5CYII=

现在,当我记录从 ActivityProviderMessage 方法返回的消息时,它看起来像这样,它应该可以正常工作(粘贴到 .html 中并打开它,链接显示图像):

<html><body>This is my html email body and here is a very long url link: <a href='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4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2sWTbmrkleKBL0qRpbiIYS1tS5itaGR5IFPuJICcRBy9ofLbgGKzIMR692aDnbhwCyLUp0gHb63XSL2sbpYyXxeRXZg+pxcc1eYy1OB22ptqKvZ1nbXHjY02FCg3lS32iKOizshLNKCI/3+73kgD3wpiIziOPYlGwOmBiqb9hbF/h90Fa7BTUfeOWx/U50mEU/3FU1WmadGpFbAL8KY9J8ftldcn+BBgAl0Jc3zM1awwAAAAASUVORK5CYII='>Long url link</a></body></html>

但是在 mail.app 中收到的电子邮件源如下所示:

<html><head><meta http-equiv=3D"content-type" content=3D"text/html; charset=3D= utf-8"></head><body dir=3D"auto"><div>This is my html email body and here is=  a very long url link: <a href=3D"data:image/png;base64,iVBORw0KGgoAAAANSUhE= UgAAAB4AAAAeCAYAAAA7MK6iAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAA= AyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVN= ME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0= YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8w= Ni0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9y= Zy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9= IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0i= aHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5h= ZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJl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1nbXHjY02FCg3lS32iKOizshLNKCI/3+73kgD3wpiIziOP= YlGwOmBiqb9hbF/h90Fa7BTUfeOWx/U50mEU/3FU1WmadGpFbAL8KY9J8ftldcn+BBgAl0Jc3zM1= awwAAAAASUVORK5CYII=3D">Long url link</a></div><div><br><br>Sent from my iPh= one</div></body></html>=

我注意到收到的电子邮件会自动包含一个新的 Head 标签,即使我在电子邮件中提供了自己的标签:

<html><head><meta http-equiv=3D"content-type" content=3D"text/html; charset=3D= utf-8"></head>

那么,要使其正常工作,是否只是为 url 找到正确格式的情况?或者当我生成电子邮件以告诉 mail.app 不要更改任何内容时,也许我需要额外的字段?

请帮忙。

谢谢

4

1 回答 1

2

如果您尝试发送带有附件的电子邮件,请使用以下方法:

- (void)addAttachmentData:(NSData*)attachment mimeType:(NSString*)mimeType fileName:(NSString*)filename

否则,如果您的目标是在邮件中显示嵌入的图像,那么您应该<img>在电子邮件正文中使用标准标签,并url指向已在网上公开提供的图像。

于 2013-07-14T18:33:54.850 回答