测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布上次发布 | 2014年12月 |
由Heitor Tashiro Sergent,Kunal Batra维护。
依赖 | |
AFNetworking | ~> 2.0 |
SMTPAPI | >= 0 |
此库允许您通过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(推荐)或源。
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."];
[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>";
此库使用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;
git checkout -b my-new-feature
)git commit -am 'Added some feature'
)git push origin my-new-feature
)许可在MIT许可证下。