SendGrid 0.3.0

SendGrid 0.3.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布上次发布2014年12月

Heitor Tashiro SergentKunal Batra维护。



 
依赖
AFNetworking~> 2.0
SMTPAPI>= 0
 

SendGrid 0.3.0

  • 作者
  • Kunal Batra和Heitor Tashiro Sergent

SendGrid-iOS

此库允许您通过Objective-C轻松快速地通过SendGrid发送电子邮件。

重要:此库需要AFNetworking 2.0或更高版本。

SendGrid *sendgrid = [SendGrid apiUser:@"username" apiKey:@"password"];   

SendGridEmail *email = [[SendGridEmail alloc] init];
email.to = @"[email protected]";
email.from = @"[email protected]";
email.subject = @"Hello World";   
email.html = @"<h1>My first email through SendGrid</h1>";
email.text = @"My first email through SendGrid";

[sendgrid sendWithWeb:email];

安装

选择您的安装方法 - CocoaPods(推荐)或源。

Podfile

platform :ios, '7.0'
pod 'SendGrid', '~>  0.2.6'

在命令行中运行以下内容

pod install

请确保现在打开.xcworkspace文件而不是.xcodeproj文件。

然后导入库 - 在适当的文件中导入。

import <SendGrid/SendGrid.h>

其他安装方法

通过源安装

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.

演示应用

GitHub仓库中的“Demo”文件夹有一个演示应用。这是一个简单的应用程序,允许您发送电子邮件,如果您想发送图片附件,还可以使用图片选择器。

要运行演示,克隆仓库(通过CocoaPods安装时不可用),打开终端并转到demo文件夹。然后执行以下操作:

pod install
open Demo.xcworkspace

使用方法

要开始使用此库,请将库导入到您的项目中。

#import <SendGrid/SendGrid.h>
#import <SendGrid/SendGridEmail.h>

使用您的SendGrid凭据创建一个新的SendGrid对象。

SendGrid *sendgrid = [SendGrid apiUser:@"username" apiKey:@"password"];

创建一个新的SendGridEmail对象,并自定义消息的参数。

SendGridEmail *email = [[SendGridEmail alloc] init];
email.to = @"[email protected]";
email.from = @"[email protected]";
email.subject = @"Hello World";   
email.html = @"<h1>My first email through SendGrid</h1>";
email.text = @"My first email through SendGrid";

发送它。

[sendgrid sendWithWeb:email];

收件人

[email addTo:@"[email protected]"];
// or
[email setTos:@[@"[email protected]"]];

发件人

[email setFrom:@"[email protected]"];

发件人姓名

[email setFromName:@"Other Dude"];

回复地址

[email setReplyTo:@"[email protected]"];

主题

[email setSubject:@"Hello World"];

文本

[email setText:@"This is some text of the email."];

HTML

[email setHtml:@"<h1>My first email through SendGrid"];

添加图片附件

您可以在电子邮件消息中添加图片附件。此方法接受一个UIImage。

[email attachImage:self.photo];

展示内联附件图片

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

X-SMTPAPI

此库使用SMTPAPI对象,该对象在SMTPAPI-iOS中找到。

替换

[header addSubstitution:@"key" val:@"value"];

NSMutableDictionary *subs = [header getSubstitutions];

独特参数

[header addUniqueArg:@"key" val:@"value"];
// or
NSMutableDictionary *uniqueArgs = [[NSMutableDictionary alloc] init];
[uniqueArgs setObject:@"value" forKey:@"unique"];
[header setUniqueArgs:uniqueArgs];

NSMutableDictionary *args = [header getUniqueArgs];

### [Categories](http://sendgrid.com/docs/API_Reference/SMTP_API/categories.html)

```objective-c
[header addCategory:@"category"];
// or
[header addCategories:@[@"category1", @"category2"]];
// or
[header setCategories:@[@"category1", @"category2"]];

NSMutableArray *cats = [header getCategories];

部分

[header addSection:@"key" val:@"section"];
// or
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;

贡献

  1. 分支
  2. 创建您的功能分支(git checkout -b my-new-feature
  3. 提交您的更改(git commit -am 'Added some feature'
  4. 将更改推送到分支(git push origin my-new-feature
  5. 创建新的拉取请求

许可证

许可在MIT许可证下。