Skip to content

This library allows you to quickly and easily send emails through SendGrid using Objective-C

Notifications You must be signed in to change notification settings

ebgraham/sendgrid-objc

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sendgrid-ios

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 *msg = [sendgrid user:@"username" andPass:@"password"];   

msg.to = @"[email protected]";
msg.subject = @"subject goes here";
msg.from = @"[email protected]";
msg.text = @"hello world";   
msg.html = @"<h1>hello world!</h1>";
    
[msg sendWithWeb];    

Installation via CocoaPods (Recommended Method)

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.

Podfile

platform :ios, '7.0'
pod 'sendgrid', '~>  0.1.0'

Run the following in the command line

pod install

Be sure to open up the xcworkspace file now instead of the xcodeproj file.

Alternative installation

Install via Source

1. Clone this repository.
2. Copy sendgrid.m and .h files to your project.
3. Import both sendgrid and AFNetworking in your project

Usage

To begin using this library, create a new email object with your SendGrid credentials.

sendgrid *msg = [sendgrid user:@"username" andPass:@"password"];

Customize the parameters of your email message.

msg.tolist = @[@"[email protected]", @"[email protected]"];
msg.subject = @"subject goes here";
msg.from = @"[email protected]";
msg.text = @"hello world";   
msg.html = @"<h1>hello world!</h1>";

For the full list of available parameters, check out the Docs

Adding To addresses

You can add a single address using the to property of the mail object

msg.to = @"[email protected]";

Or

You can add multiple To addresses by setting the toList property

msg.tolist = @[@"[email protected]", @"[email protected]"];

Note One or the other must be set.

Adding an image attachment

You can add an image attachment to your email message. The method accepts a UIImage.

[msg attachImage:self.photo];

Displaying attached image inline

msg.inlinePhoto = true;
msg.html = @"<img src =\"cid:image.png\"><h1>hello world</h1>";

Adding custom headers

You can set custom headers in your email by using the addCustomHeader:withKey method.

Adding Categories

NSString *cat = @"billing_notifications";
[msg addCustomHeader:cat withKey:@"category"];

Adding Unique Arguments

NSDictionary *uarg = @{@"customerAccountNumber":@"55555",
                           @"activationAttempt": @"1"};

[msg addCustomHeader:uarg withKey:@"unique_args"];

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

This library allows you to quickly and easily send emails through SendGrid using Objective-C

Resources

Stars

Watchers

Forks

Packages

No packages published