我如何从iPhone发送电子邮件? [英] How i send email from IPhone?

查看:114
本文介绍了我如何从iPhone发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在特定的timeInterval上自动向iphone发送电子邮件给发件人(硬编码的电子邮件ID)。如何在不使用MFMailComposeViewController类的UI的情况下自动发送电子邮件?



谢谢。

解决方案

内置框架中没有任何内容可以允许它。您当然可以使用unix套接字api连接到邮件服务器并使用SMTP发送邮件,但是有一些第三方ibraries可以让您的生活更轻松。



我使用了Pantomine消息库。它适用于iOS,可在 http://www.collaboration-world.com/pantomime/ 上找到/ p>

在项目中拥有库后,您可以执行以下操作:

  CWMessage * message = [[CWMessage alloc] init]; 

CWInternetAddress * from = [[CWInternetAddress alloc] initWithString:@from@gmail.com];
[message setFrom:from];
[发布时间];

CWInternetAddress * to = [[CWInternetAddress alloc] initWithString:@to@somewhere.com];
[地址setType:PantomimeToRecipient];
[message addRecipient:to];
[发布];

[message setSubject:@这是我的主题];

[message setContentType:@text / plain];
[message setContentTransferEncoding:PantomimeEncodingNone];
[message setCharset:@us-ascii];

[message setContent:[@这是我的消息dataUsingEncoding:NSASCIIStringEncoding]];

smtp = [[CWSMTP alloc] initWithName:@smtp.gmail.comport:465];
[smtp setDelegate:self];
[smtp setMessage:message];
[消息发布];

ssl = YES;
mechanism = @PLAIN;

[smtp connectInBackgroundAndNotify];


I want to send automatically an email to sender (hard coded email id) from iphone on particular timeInterval. How i send an email automatically without using UI of MFMailComposeViewController class?

Thanks.

解决方案

There is nothing in the built in frameworks that will allow it. You could of course use the unix sockets api to conect to a mail server and send a message using SMTP, however there are some third party ibraries to make your life easier.

I have used the Pantomine messaging library. It works well on iOS and can be found at http://www.collaboration-world.com/pantomime/

Once you have the library in your project you can do something like this:

CWMessage *message = [[CWMessage alloc] init];

CWInternetAddress *from = [[CWInternetAddress alloc] initWithString:@"from@gmail.com"];
[message setFrom:from];
[from release];

CWInternetAddress *to = [[CWInternetAddress alloc] initWithString:@"to@somewhere.com"];
[address setType:PantomimeToRecipient];
[message addRecipient:to];
[to release];

[message setSubject:@"This is my subject"];

[message setContentType: @"text/plain"];
[message setContentTransferEncoding: PantomimeEncodingNone];
[message setCharset: @"us-ascii"];

[message setContent: [@"This is my message" dataUsingEncoding: NSASCIIStringEncoding]];

smtp = [[CWSMTP alloc] initWithName:@"smtp.gmail.com" port:465];
[smtp setDelegate: self];
[smtp setMessage: message];
[message release];

ssl = YES;
mechanism = @"PLAIN";

[smtp connectInBackgroundAndNotify];

这篇关于我如何从iPhone发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆