脚本桥在添加收件人到邮件时添加不需要的HTML代码 [英] Scripting Bridge adds unwanted HTML code when adding recipient to mail

查看:112
本文介绍了脚本桥在添加收件人到邮件时添加不需要的HTML代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这个有点奇怪....

Ok, so this one is a bit strange....

我在Safari中有一个HTML页面,我想通过电子邮件发送。

I have an HTML page in Safari which I want to send as an email. If I go the FILE menu and select "Mail Contents of this Page", it transfers as expected and looks correct.

但是,如果我使用Scripting Bridge添加收件人到这个页面的邮件内容,传出消息,它将添加以下代码到每个收件人添加的消息内容区域的顶部。在一个示例中,添加了24个收件人,生成的电子邮件包含以下代码的24个连续重复:

However, if I use Scripting Bridge add recipients to the outgoing message, it adds the following code to the top of the message content area for EACH recipient added. In one example, with 24 recipients added, the resulting email contains 24 sequential repeats of the following code:

<div style=3D"font-family: = Helvetica; font-size: 12px; color: black; text-align: left;">
<br =class=3D"webkit-block-placeholder"></div>

这是因为div标签的呈现方式,在电子邮件开头创建了24个换行符

which because of the way the div tag is rendered, creates 24 line breaks at the beginning of the email so that my HTML begins further down the page.

任何人都知道为什么要插入此代码?

Anyone know why this code is getting inserted?

是我用于脚本桥的代码:

Here is the code I'm using for Scripting Bridge:

SafariDocument *safariDoc = [[[[safari classForScriptingClass:@"document"] alloc]
initWithProperties:[NSDictionary dictionaryWithObject:@"//private/var/tmp/mail.html" forKey: @"URL"]] autorelease];
    [[safari documents] addObject:safariDoc];

SafariWindow *safariWindow = [[safari windows] objectAtIndex:0];
        [safariWindow emailContentsOf:safariWindow.currentTab];
        mailMessage = [[[mail outgoingMessages] objectAtIndex:0] autorelease];

以下是我用于添加收件人的代码:

Here is the code I use to add recipients:

MailToRecipient *recipient = [[[[mail classForScriptingClass:@"to recipient"] alloc] 
                                   initWithProperties:[NSDictionary dictionaryWithObjectsAndKeys:
                                                       [preferencesData bandName], @"name",
                                                       [preferencesData bandEmail], @"address",
                                                       nil]] autorelease];
    [[mailMessage toRecipients] addObject:recipient];

* EDIT *

我已经找到一个解决问题的工作,但我仍然有兴趣知道为什么这个代码正在插入到身体,当我添加一个收件人...工作如下:我插入以下到我的HTML模板的CSS部分...

I have found a work around for the problem, but I would still be interested in knowing WHY this code is getting inserted into the body when I add a recipient... The work around is as follows: I inserted the following into the CSS section of my HTML template...

div {
display:none;
}

因此,显示忽略html模板中的所有div标记。我仍然有24个上述代码的副本,但它们基本上被忽略,这解决了我的视觉布局问题。

Thus, the display ignores all of the div tags in the html template. I still have 24 copies of the above code, but they are essentially ignored which solves my visual layout problem.

如果任何人有更好的解决方案,请让我知道! / p>

If anyone has a better solution, please let me know!

推荐答案

似乎苹果不允许您访问您没有拥有程序。

It seems that Apple does not allow you to access outgoing mail messages which you do not "own" or have created from within your program.

在上面的代码中,我试图解决苹果的限制,不允许你将发送的电子邮件设置为HTML(别的,他们不喜欢你通过使用Safari电子邮件内容的网页,从而在Apple Mail中创建新的外发邮件消息。

In the code above, I was trying to work around Apple's limitation of not letting you set your outgoing email to HTML (something else they don't like you to do) by having Safari "email contents of web page", thereby creating a new outgoing mail message in Apple Mail.

然后我试图控制该消息

mailMessage = [[[mail outgoingMessages] objectAtIndex:0] autorelease];

有一点研究表明,尽管下面的代码,mailMessage显示为nil p>

A bit of research revealed that mailMessage was showing as "nil" even though the following code:

[[mail outgoingMessages] count];

正在返回正确的值1.

was returning the correct value of 1.

所以在理论上,我不应该能够添加收件人到Safari创建的HTML电子邮件。

So in theory, I shouldn't be able to add recipients to the HTML email created by Safari at all.

为什么它有时工作,不工作其他时代超越我。但是当它工作时,它也将格式化标签添加到代码的主体中。我怀疑这只是一个没有被捕获的错误,因为它根本不应该工作。

Why it works sometimes and doesn't work other times is beyond me. But when it does work, it also adds formatting tags into the body of the code as well. I suspect it's just a bug that hasn't been caught since it shouldn't be working at all.

这篇关于脚本桥在添加收件人到邮件时添加不需要的HTML代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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