This library allows you to quickly and easily send emails through SendGrid using Objective-C.
Important: This library requires AFNetworking 2.0 or higher.
SendGrid *sendgrid = [SendGrid apiUser:@"username" apiKey:@"password"];
SendGridEmail *email = [[SendGridEmail alloc] init];
email.to = @"example@example.com";
email.from = @"other@example.com";
email.subject = @"Hello World";
email.html = @"<h1>My first email through SendGrid</h1>";
email.text = @"My first email through SendGrid";
[sendgrid sendWithWeb:email];
Choose your installation method - CocoaPods (recommended) or source.
CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like SendGrid and its dependencies in your projects. Simply add the lines below to your existing Podfile or make a new 'Podfile' that contain the lines below.
platform :ios, '7.0'
pod 'SendGrid', '~> 0.2.6'
Run the following in the command line:
pod install
Be sure to open up the .xcworkspace file now instead of the .xcodeproj file.
Then import the library - in the file appropriate to your project.
import <SendGrid/SendGrid.h>
Install via Source
1. Clone this repository.
2. Copy SendGrid.h and .m files to your project.
3. Clone the [SMTPAPI repository](https://github.com/heitortsergent/smtpapi-ios).
4. Copy SMTPAPI.h and .m files to your project.
5. Import SendGrid.h in the file appropriate to your project, and AFNetworking in your project.
There's a demo app on the Github repository, inside the folder "Demo". It's a simple application that lets you send an email, with an Image Picker if you want to send a picture attachment with it.
To run the demo, clone the repository (it's not available when you install via CocoaPods), open the terminal and go to the demo folder. Then do:
pod install
open Demo.xcworkspace
To begin using this library, import the library into your project.
#import <SendGrid/SendGrid.h>
#import <SendGrid/SendGridEmail.h>
Create a new SendGrid object with your SendGrid credentials.
SendGrid *sendgrid = [SendGrid apiUser:@"username" apiKey:@"password"];
Create a new SendGridEmail object, and customize the parameters of your message.
SendGridEmail *email = [[SendGridEmail alloc] init];
email.to = @"example@example.com";
email.from = @"other@example.com";
email.subject = @"Hello World";
email.html = @"<h1>My first email through SendGrid</h1>";
email.text = @"My first email through SendGrid";
Send it.
[sendgrid sendWithWeb:email];
You can add one or multiple TO addresses using addTo
.
[email addTo:@"foo@example.com"];
[email addTo:@"bar@example.com"];
[email setTos:@[@"foo@example.com", @"bar@example.com"]];
[email addBcc:@"foo@example.com"];
[email setFrom:@"other@example.com"];
[email setFromName:@"Other Dude"];
[email setReplyTo:@"no-reply@nowhere.com"];
[email setSubject:@"Hello World"];
[email setText:@"This is some text of the email."];
[email setHtml:@"<h1>My first email through SendGrid"];
[email addSubstitution:@"key" val:@"value"];
[email addUniqueArg:@"key" val:@"value"];
[email addCategory:@"category"];
[email addSection:@"key" val:@"value"];
[email addFilter:@"filter" setting:@"setting" val:@"value"];
[email addFilter:@"filter" settings:@"setting" val:1];
You can add an image attachment to your email message. The method accepts a UIImage.
[email attachImage:self.photo];
Displaying attached image inline
email.inlinePhoto = true;
email.html = @"<img src =\"cid:image0.png\"><h1>hello world</h1>";
UIImage *sendgridLogo = [UIImage imageNamed:@"sendgrid_logo.png"];
SendGridEmailAttachment* someImageAttachment = [[SendGridEmailAttachment alloc] init];
someImageAttachment.attachmentData = UIImagePNGRepresentation(sendgridLogo);
someImageAttachment.mimeType = @"image/png";
someImageAttachment.fileName = @"sendgrid_logo";
someImageAttachment.extension = @"png";
[email attachFile:someImageAttachment];
This library uses the SMTPAPI object which is found in SMTPAPI-iOS.
[header addSubstitution:@"key" val:@"value"];
NSMutableDictionary *subs = [header getSubstitutions];
[header addUniqueArg:@"key" val:@"value"];
[header addUniqueArg:@"key2" val:@"value2"];
NSMutableDictionary *args = [header getUniqueArgs];
NSMutableDictionary *uniqueArgs = [[NSMutableDictionary alloc] init];
[uniqueArgs setObject:@"value" forKey:@"unique"];
[header setUniqueArgs:uniqueArgs];
NSMutableDictionary *args = [header getUniqueArgs];
[header addCategory:@"category1"];
[header addCategory:@"category2"];
NSMutableArray *cats = [header getCategories];
[header addCategories:@[@"category1", @"category2"]];
NSMutableArray *cats = [header getCategories];
[header setCategories:@[@"category1", @"category2"]];
NSMutableArray *cats = [header getCategories];
[header addSection:@"key" val:@"section"];
NSMutableDictionary *sections = [header getSections];
NSMutableDictionary *newSec = [[NSMutableDictionary alloc] init];
[newSec setObject:@"value" forKey:@"-section-"];
[header setSections:newSec];
NSMutableDictionary *sections = [header getSections];
[header addFilter:@"filter" setting:@"setting" val:@"value"];
[header addFilter:@"filter" settings:@"setting" val:1];
NSMutableDictionary *filters = [header getFilters];
[header configureHeader];
NSString *headers = header.encodedHeader;
git checkout -b my-new-feature
)git commit -am 'Added some feature'
)git push origin my-new-feature
)Licensed under the MIT License.