我正在使用gmail API
我使用GTLGmailMessage
发送电子邮件。
当我尝试通过将其设置为GTLGmailMessage.raw
来发送正常短信时,它已成功发送。
我尝试使用HTML内容相同的代码。它已成功发送邮件,但html内容源正在收到的电子邮件中显示。
以下是我准备原始电子邮件正文的代码:
private func generateRawString() -> String {
let dateFormatter: DateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss Z"; //RFC2822-Format
let todayString: String = dateFormatter.string(from: Date())
let externalDataSource = self.emailActivity.storedInServerFolder?.forEmailAccount?.externalDataSource
let senderEmail: String = (externalDataSource?.userName)!
let senderName: String = (emailActivity.activityOwner?.leFullName)!
var rawMessage = ""
var bodyText = ""
var bodyHTML = ""
rawMessage = rawMessage + "Date: \(todayString)\r\n"
rawMessage = rawMessage + "From: \(senderName) <\(senderEmail)>\r\n"
rawMessage = rawMessage + addParticipants(with: Constants.ActivityRoleTypes.kKeyActivityTypeEmailRoleTo, roleType: "To: ")
rawMessage = rawMessage + addParticipants(with: Constants.ActivityRoleTypes.kKeyActivityTypeEmailRoleCc, roleType: "Cc: ")
rawMessage = rawMessage + addParticipants(with: Constants.ActivityRoleTypes.kKeyActivityTypeEmailRoleBcc, roleType: "Bcc: ")
rawMessage = rawMessage + "Subject: \((emailActivity.activityName)!)\r\n\r\n"
if let actDesc = emailActivity.activityDescription{
bodyText = actDesc
bodyText = bodyText.replacingOccurrences(of: "\n", with: "<br>")
}
if let htmlContent = emailActivity.activityHtmlContent {
bodyHTML = htmlContent
}
var finalHTMLBody = self.createHTMLBody(bodyText: bodyText, htmlContent: bodyHTML)
finalHTMLBody += "\r\n\r\n" + Constants.PLACE_HOLDERS.kEmailDraftBody
rawMessage = rawMessage + finalHTMLBody
return GTLEncodeWebSafeBase64(rawMessage.data(using: String.Encoding.utf8))
这是我用来发送邮件的代码的参考链接。 How send Email using Gmail api in swift
用Google搜索了很多。是否有针对html特定部分的编码/解码?
提前致谢。
参考:正在使用的Github库中创建了问题:https://github.com/google/google-api-objectivec-client-for-rest/issues/206