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.
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.
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!");
}
}];
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];