我正在开发一个应用程序,在这个应用程序中,我不使用IOS邮件API发送邮件(邮件是使用SES amazon服务的发件人,不需要用户和附加文件的交互…)。在我的API中,我必须发送带有所有MIME协议的编码邮件(这不是问题)。我用字符集ascii和我在base64中附加的pdf对正文进行编码:
CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);
NSString *uuid = (__bridge_transfer NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuidRef);
CFRelease(uuidRef);
//Encapsulation
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableString *rawMime = [[NSMutableString alloc] init];
[rawMime appendFormat:@"To: %@\n", _to];
[rawMime appendFormat:@"From: \"%@\" <boutique@tactill.com>\n", [defaults objectForKey:@"companyName"]];
[rawMime appendFormat:@"Reply-To: %@\n", [defaults objectForKey:@"toEmailForStats"]];
[rawMime appendFormat:@"BCC: %@\n", [defaults objectForKey:@"toEmailForStats"]];
[rawMime appendFormat:@"Subject: %@\n", _subject];
[rawMime appendString:@"Date: Thu, 05 Jan 95 10:53:24 -0500\n"];
[rawMime appendFormat:@"Message-ID: <%@@%@>\n", [(NSString *)uuid stringByReplacingOccurrencesOfString:@"-" withString:@""], @"IETF.CNR I.Reston.VA.US"];
[rawMime appendString:@"Mime-Version: 1.0\n"];
[rawMime appendString:@"Content-type: Multipart/Mixed; boundary=\"NextPart\"\n"];
[rawMime appendString:@"\n"];
[rawMime appendString:@"--NextPart\n"];
//Body
[rawMime appendString:@"Content-type: text/plain; charset=\"us-ascii\"\n"];
[rawMime appendString:@"\n"];
[rawMime appendString:_body];
[rawMime appendString:@"\n"];
[rawMime appendString:@"--NextPart\n"];
//Attach pdf
[rawMime appendString:@"Content-Type: application/pdf; "];
[rawMime appendFormat:@"name=\"%@.pdf\";\n", _pdfName];
[rawMime appendFormat:@"Content-Transfer-Encoding: base64\r\n\r\n"];
[rawMime appendFormat:@"%@\n",_pdfAttached];
[rawMime appendString:@"\n"];
//If necessary attach csv
if (_csvAttached!=nil) {
[rawMime appendString:@"--NextPart\n"];
[rawMime appendString:@"Content-Type: text/plain; "];
[rawMime appendFormat:@"name=\"%@.txt\";\n", _csvName];
[rawMime appendFormat:@"Content-Transfer-Encoding: base64\r\n\r\n"];
[rawMime appendFormat:@"%@\n",_csvAttached];
[rawMime appendString:@"\n"];
[rawMime appendString:@"--NextPart\n"];
}
NSData *rawMessageData = [rawMime dataUsingEncoding:NSUTF8StringEncoding];
当我用gmail或邮件应用程序(OSX或IOS)打开邮件时,一切都很完美,但当我用windows mail打开邮件时,特殊字符被更改为垃圾邮件。我已经读过了,我看到windows mail读iso-8859-1(NSISOLatin1StringEncoding)。所以我在那篇文章的帮助下试过:[http://stackoverflow.com/questions/4553388/how-to-convert-utf8-encoding-to-iso-8859-1-encoding][1] 执行该代码:
//add body
char converted[([_body length] + 1)];
[_body getCString:converted maxLength:([_body length] + 1) encoding: NSISOLatin1StringEncoding];
[rawMime appendString:@"Content-type: text/plain; charset=iso-8859-1\n"];
[rawMime appendFormat:@"Content-Transfer-Encoding: quoted-printable\r\n\r\n"];
[rawMime appendFormat:@"%s", converted];
[rawMime appendString:@"\n"];
[rawMime appendString:@"--NextPart\n"];
现在所有的邮件客户都向我展示了这个:谢谢你。™t!当我只打印身体时,NSLog也是如此我做错了什么?如何对邮件正文进行编码?
这里有一个工作代码来回答这个问题,它添加了一个pdf,偶尔也添加了一个csv
-(NSData*)formatedMail{
CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);
NSString *uuid = (__bridge_transfer NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuidRef);
CFRelease(uuidRef);
NSDate* today = [[NSDate alloc] init];
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSString* date =[dateFormatter stringFromDate:today];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableString *rawMime = [[NSMutableString alloc] init];
[rawMime appendFormat:@"To: %@\n", email_to];
[rawMime appendFormat:@"From: \"name_from" <e-mail_from>\n", [defaults objectForKey:@"companyName"]];
[rawMime appendFormat:@"Reply-To: %@\n", [defaults objectForKey:@"toEmailForStats"]];
[rawMime appendFormat:@"BCC: %@\n", [defaults objectForKey:@"toEmailForStats"]];
[rawMime appendFormat:@"Subject: %@\n", _subject];
[rawMime appendFormat:@"Date: %@\n", date];
[rawMime appendFormat:@"Message-ID: <%@@%@>\n", [(NSString *)uuid stringByReplacingOccurrencesOfString:@"-" withString:@""], @"IETF.CNR I.Reston.VA.US"];
[rawMime appendString:@"Mime-Version: 1.0\n"];
[rawMime appendString:@"Content-type: Multipart/Mixed; boundary=\"NextPart\"\n"];
[rawMime appendString:@"\n"];
[rawMime appendString:@"--NextPart\n"];
//Here's come the body part
[rawMime appendString:@"Content-type: text/plain; charset=\"UTF-8\"\n"];
[rawMime appendString:@"\n"];
[rawMime appendString:_body];
[rawMime appendString:@"\n"];
[rawMime appendString:@"--NextPart\n"];
//Attach pdf
[rawMime appendString:@"Content-Type: application/pdf; "];
[rawMime appendFormat:@"name=\"%@.pdf\";\n", _pdfName];
[rawMime appendFormat:@"Content-Transfer-Encoding: base64\r\n\r\n"];
[rawMime appendFormat:@"%@\n",_pdfAttached];
[rawMime appendString:@"\n"];
//If necessary attach csv
if (_csvAttached!=nil) {
[rawMime appendString:@"--NextPart\n"];
[rawMime appendString:@"Content-Type: application/octet-stream; "];
[rawMime appendFormat:@"name=\"%@\";\n", _csvName];
[rawMime appendFormat:@"Content-Transfer-Encoding: base64\r\n\r\n"];
[rawMime appendFormat:@"%@\n",_csvAttached];
[rawMime appendString:@"\n"];
[rawMime appendString:@"--NextPart\n"];
}
NSData *rawMessageData = [rawMime dataUsingEncoding:NSUTF8StringEncoding];
return rawMessageData;
}
pdfAttached是NSString,表示用base64编码的PDF。我希望这有帮助,很抱歉,在此之前没有发布解决方案
这里的代码不是发送,而是创建邮件正文。在这里,您可以执行使用sessendrawmailrequest无法执行的操作,例如,将“show name”与at to和from放在一起。我建议您使用这两个部分来定义发件人,您将看到它提供了只有SESSendRawMessage无法提供的可能性。最后说,如果您不想出现异常,您不应该忘记在SESSEndRawEmailRequest中放置收件人和发件人地址。
我正在为我的Web应用程序构建一个邮件模块。在我目前的位置上,我正在尝试获取邮件正文并正确解码。但是,当我在邮件中遇到国际字符时,它无法正确解码它们。 例如。我有一个原始的电子邮件正文: 这是解码后的结果: 应该是。我只在处理国际字符时见过这个问题。有人知道如何修复它吗?我在下面包含了我的解码代码。它取自http://www.sitepoint.com/exploring-phps-imap-li
我有一个gmail帐户链接到我的域名帐户。 AWS SES将向我的S3存储桶发送消息。从那里,SNS将把原始格式的信息转发到我的gmail地址。 如何将原始邮件自动转换为标准电子邮件格式?
我创建了一个子域sesmail.xxxx.com使用Cboard其中xxxx是我的域。 将其设置为Amazon SES的“来自域的邮件”,并将MX和TXT条目添加到我的DNS区域。亚马逊SES成功地验证了它。 我可以发送和接收电子邮件到外部域名,如gmail,雅虎等。然而,我不能发送电子邮件到我自己的域名。 打开通知,我发现邮件被此错误反弹- 外部我可以发送和接收没有问题。在内部,当我给自己发送电
我的代码如下: 属性包括: 主机=smtp.gmail.com mail.smtp.auth=true mail.smtp.starttls.enable=true mail.smtp.host=smtp.gmail.com mail.smtp.port=587 mail.mime.charset=UTF-8 注意:文本在发送之前没有损坏。message.getSubject()打印出来的是干净的
我也遇到了一个问题,而发送邮件正文的日语。 我使用了mimeutility.encodeText(subject,“UTF-8”,“B”),但这只适用于subject而不适用于邮件正文中的日语文本。 我正在使用阿帕奇骆驼邮件。 请帮忙
The Python Imaging Library uses a plug-in model which allows you to add your own decoders to the library, without any changes to the library itself. Such plug-ins usually have names like XxxImagePlugi