IOS Is it possible to enter HTML code in an email application for sending by mail?

We are engaged in clerical business and develop postal stationery, signatures, etc. for people. There is no problem using them on a PC, because it’s easy to add HTML to email content in most email clients. However, is this possible with iOS?

As we now do this for mobile devices, we tell users to add our SMTP server and send messages through it. How this SMTP works, it wraps each email with HTML before sending. I wonder if this can be done right on the iPhone with some kind of post-processing of emails before sending?

+5
source share
4 answers

AFAIK, you cannot catch emails sent from the built-in email client. However, you can write your own application that sends emails using HTML using MFMailComposeViewController.

EDIT: added sample code:

- (void) sendEventInEmail
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    [picker setSubject:@"Email Subject"];

    // Fill out the email body text
    NSString *iTunesLink = @"http://itunes.apple.com/gb/app/whats-on-reading/id347859140?mt=8"; // Link to iTune App link
    NSString *content = [eventDictionary objectForKey:@"Description"];
    NSString *imageURL = [eventDictionary objectForKey:@"Image URL"];
    NSString *findOutMoreURL = [eventDictionary objectForKey:@"Link"];

    NSString *emailBody = [NSString stringWithFormat:@"<br /> <a href = '%@'> <img src='%@' align=left  style='margin:5px' /> </a> <b>%@</b> <br /><br />%@ <br /><br />Sent using <a href = '%@'>What On Reading</a> for the iPhone.</p>", findOutMoreURL, imageURL, emailSubject, content, iTunesLink];

    [picker setMessageBody:emailBody isHTML:YES];

    [self presentModalViewController:picker animated:YES];

[picker release];
    }

 - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
    {
        // Notifies users about errors associated with the interface
        switch (result)
        {
            case MFMailComposeResultCancelled:
                break;
            case MFMailComposeResultSaved:
                break;
            case MFMailComposeResultSent:
                break;
            case MFMailComposeResultFailed:
                break;
            default:
                break;
        }
        [self dismissModalViewControllerAnimated:YES];
    }
+11
source

It should look something like this:

    // Compose body
    NSMutableString *emailBody = [[[NSMutableString alloc] initWithString:@"<html><body>"] autorelease];
    [emailBody appendString:@"<p>Hi<br><br>THis is some HTML</p>"];        
    [emailBody appendString:@"</body></html>"];

    // Compose dialog
    MFMailComposeViewController *emailDialog = [[MFMailComposeViewController alloc] init];
    emailDialog.mailComposeDelegate = self;

    [emailDialog setToRecipients:[NSArray arrayWithObject:@"test@test.com"]];

    // Set subject
    [emailDialog setSubject:@"I got a question!"];

    // Set body
    [emailDialog setMessageBody:emailBody isHTML:YES];

    // Show mail
    [self presentModalViewController:emailDialog animated:YES];
    [emailDialog release];

As said above, don't forget delegate 8)

NTN Marcus

+1
source

MFMailComposeViewController, HTML . , . . :

- (void)setMessageBody:(NSString*)body isHTML:(BOOL)isHTML
- (void)addAttachmentData:(NSData*)attachment mimeType:(NSString*)mimeType fileName:(NSString*)filename

0

( stringWithFormat: NSMutableString), html. MFMailComposeViewController -(void)setMessageBody:(NSString*)body isHTML:(BOOL)isHTML

:

 NSString *bodyText = [[NSString alloc] initWithFormat:@"<html><p>%@</p></html", bodyField.text];  //Not an HTML expert

bodyText.

0
source

All Articles