Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7977945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:21:14+00:00 2026-06-04T09:21:14+00:00

I’m developping an app where I send mail without the IOS mail API(the mail

  • 0

I’m developping an app where I send mail without the IOS mail API(the mail is sender with SES amazon service without the interaction of the user and attaching files…). In my API I have to send the encoded mail with all the MIME protocol(that’s not the problem). I send well mails encoding the body with charset ascii and the pdf I attach in 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];

When I open the mail with gmail or mail app(OSX or IOS) all is perfect but when I open it with windows mail the special characters are changed for junk. I have read about it and I have see that windows mail reads iso-8859-1(NSISOLatin1StringEncoding). So I have tried with the help of that post: [http://stackoverflow.com/questions/4553388/how-to-convert-utf8-encoding-to-iso-8859-1-encoding][1] do that code:

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

Now all the mail clients show me this:Merci pour votre achat. ¿ bientÙt! as do NSLog when I print only the body
What I’m doing wrong? how I can encode well the body of the mail?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:21:15+00:00Added an answer on June 4, 2026 at 9:21 am

    Here’s a working code to answer this question that adds a pdf and occasionally a csv too

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

    The _pdfAttached is NSString representing the PDF encoded in base64
    I hope it helps and sorry to don’t post the solution before

    Here’s the code not to send but to create the mail body. Here you could do things that you couldn’t do using SESSendRawEmailRequest, for example put a “show name” with at to and from. I suggest you to use the two parts to define the senders and u will see it offers possibilities that only SESSendRawMessage can’t offer. Finally say that you should not forget to put the to and from addresses at the SESSEndRawEmailRequest if you not want to have an exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need to clean up various Word 'smart' characters in user input, including but
I am writing an app with both english and french support. The app requests
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.