IOS que codifica el correo del cuerpo (creando el correo mimo propio para SES)

Estoy desarrollando una aplicación donde envío correo sin la API de correo IOS (el correo es remitente con el service SES amazon sin la interacción del usuario y adjuntando files …). En mi API tengo que enviar el correo codificado con todo el protocolo MIME (ese no es el problema). Envío correos electrónicos que codifican el cuerpo con charset ascii y el pdf adjunto en base64:

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]; 

Cuando abro el correo con gmail o aplicación de correo (OSX o IOS), todo es perfecto, pero cuando lo abro con Windows Mail, los caracteres especiales se cambian por basura. Lo he leído y veo que el correo de Windows lee iso-8859-1 (NSISOLatin1StringEncoding). Así que he intentado con la ayuda de esa publicación: [http://stackoverflow.com/questions/4553388/how-to-convert-utf8-encoding-to-iso-8859-1-encoding][1] hacer ese código :

  //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"]; 

Ahora todos los clientes de correo me muestran esto: Merci pour votre achat. ¡Bient no! al igual que NSLog cuando imprimo solo el cuerpo ¿Qué estoy haciendo mal? ¿Cómo puedo codificar bien el cuerpo del correo?

Aquí hay un código de trabajo para responder a esta pregunta que agrega un pdf y ocasionalmente un CSV también

 -(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; } 

El _pdfAttached es NSString que representa el PDF codificado en base64. Espero que sea útil y lo siento por no publicar la solución antes

Aquí está el código para no enviar sino para crear el cuerpo del correo. Aquí puede hacer cosas que no pudo hacer usando SESSendRawEmailRequest, por ejemplo, poner un "nombre de muestra" en ay. Le sugiero que use las dos partes para definir los remitentes y verá que ofrece posibilidades que SESSendRawMessage no puede ofrecer. Finalmente, diga que no debe olvidar poner las direcciones de input y salida en SESSEndRawEmailRequest si no desea tener una exception.