0

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.

Tirth
  • 7,801
  • 9
  • 55
  • 88

1 Answers1

5

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];
Brad The App Guy
  • 16,255
  • 2
  • 41
  • 60