CGLMail makes it easy to send email from any class in your app, without implementing the MFMailComposeViewControllerDelegate
protocol all over the place. It was initially written to centralize the submission of feedback emails into one class.
If you're using cocoapods like you should, add CGLMail to your podfile:
pod 'CGLMail', '~> 0.1'
For example, you can get a view controller to send an email like so:
UIViewController *mailVC = [CGLMailHelper mailViewControllerWithRecipients:@[@"[email protected]"]
subject:@"Hi Mom!"
message:@"Hi Mom, \n\nJust wanted to check in and say hello!\n\nLove, \nChris"
isHTML:NO
includeAppInfo:NO
completion:nil];
Which would end up looking somthing like this:
Or, to generate a user support email, with diagnostic info about the user's app and device:
UIViewController *mailVC = [CGLMailHelper supportMailViewControllerWithRecipient:@"[email protected]"
subject:@"Support Email"
completion:nil];
Which would yield a view controller that looks like this:
Note that CGLMailHelper will return nil if [MFMailComposeViewController canSendMail]
returns NO
, e.g. if the user has not yet set up her email address. Be sure to check for nil! UIKit will throw an exception if you try to present a nil view controller.