0

any one knows an objective-c smtp library for use in iphone app.

I use skpsmtpmessage http://code.google.com/p/skpsmtpmessage/ but it sends message body as attachment when send mail to gmail.

thanks.

aminhotob
  • 1,056
  • 14
  • 17
  • Then you are not using it correctly. Can you provide the code? that could help. – Rigo Vides Dec 17 '10 at 17:50
  • Now I use "MFMailComposeViewController" it is a part of "MessageUI.framework" http://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html – aminhotob Dec 19 '10 at 14:13

2 Answers2

4

Try to use https://github.com/MailCore/mailcore2. It is Asynchronous and support most of mail protocol.

Look at the Sending Mail Example:

 MCOSMTPSession *smtpSession = [[MCOSMTPSession alloc] init];
 smtpSession.hostname = @"smtp.gmail.com";
 smtpSession.port = 465;
 smtpSession.username = @"matt@gmail.com";
 smtpSession.password = @"password";
 smtpSession.authType = MCOAuthTypeSASLPlain;
 smtpSession.connectionType = MCOConnectionTypeTLS;

 MCOMessageBuilder *builder = [[MCOMessageBuilder alloc] init];
 MCOAddress *from = [MCOAddress addressWithDisplayName:@"Matt R"
                                      mailbox:@"matt@gmail.com"];
 MCOAddress *to = [MCOAddress addressWithDisplayName:nil 
                                    mailbox:@"hoa@gmail.com"];
 [[builder header] setFrom:from];
 [[builder header] setTo:@[to]];
 [[builder header] setSubject:@"My message"];
 [builder setHTMLBody:@"This is a test message!"];
 NSData * rfc822Data = [builder data];

   MCOSMTPSendOperation *sendOperation = 
   [smtpSession sendOperationWithData:rfc822Data];
   [sendOperation start:^(NSError *error) {
   if(error) {
       NSLog(@"Error sending email: %@", error);
   } else {
       NSLog(@"Successfully sent email!");
   }
}];
Eugene P
  • 554
  • 4
  • 19
0

I use the same library in one of my iOS app. I successfully send the message text, attachments and all. Here is the portion of my code for the message text body:

NSString *messageBody = @"xxxxxx";

// Now creating plain text email message
NSDictionary *plainMsg = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey, messageBody,kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];
emailMessage.parts = [NSArray arrayWithObjects:plainMsg,nil];

[emailMessage send];
Panayot
  • 484
  • 1
  • 6
  • 18