【问题标题】:Format body of email using SkpsmtpMessage library使用 SkpsmtpMessage 库格式化电子邮件正文
【发布时间】:2012-04-28 22:57:03
【问题描述】:

我在我的项目中使用 SkpsmtpMessage 库,一切正常。 问题在于电子邮件正文的布局。我想以漂亮的布局显示它,例如粗体名称,然后想将图像嵌入其中,以便在客户打开电子邮件等时显示。 现在我只是在使用

NSString * bodyMessage = [NSString stringWithFormat:@"Dear %@:\n \nThank you for reserving your holiday  with us. Your order is now confirmed - 
see below your details including your order reference number and your chosen collection point. ",%@];  

它只是演示。 那么我怎样才能像我们在其他电子邮件客户端中那样正确格式化它。

提前谢谢你。

解决方案:

使用

 NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/html",kSKPSMTPPartContentTypeKey,
                           body ,kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];

即 text/html 而不是 text/plain。

代码是

SKPSMTPMessage  *testMsg = [[SKPSMTPMessage alloc] init];
NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/html",kSKPSMTPPartContentTypeKey,
                           body ,kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];
testMsg.parts = [NSArray arrayWithObjects:plainPart,nil];

[testMsg send];

这里的 body 是包含 html 文本的 NSString...

谢谢。希望其他人可以使用它。

【问题讨论】:

  • 非常感谢......我正要浪费我的时间......

标签: ios


【解决方案1】:

类本身的文档说:

SKPSMTPMessage 是一个快速而肮脏的类,它为 iPhone 实现了一个基本的 SMTP 客户端。如果您只想在 iPhone 上发布纯文本或 HTML 消息,请使用 -[UIApplication openURL:](这些不是您要寻找的机器人,继续前进,继续前进)。但是,如果您尝试将文件附加到电子邮件中,或者做其他疯狂的事情,您会想要使用这个类。

此外,它最后一次更新是在 2009 年 2 月,距今已超过 3 年。

虽然不是直接回答您的问题 - 更好的解决方案是不使用此框架。

【讨论】:

  • SKPSMTPMessage 还有其他替代方案吗?我可以在哪里发布 html 消息和嵌入图片?
  • Abizern 检查解决方案伴侣... 现在排序。还是谢谢你的回复
猜你喜欢
  • 2014-02-10
  • 2011-06-02
  • 2020-05-09
  • 1970-01-01
  • 2016-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多