клиентская библиотека iphone smtp - PullRequest
0 голосов
/ 09 августа 2010

любой знает, что smtp-библиотека target-c предназначена для использования в приложении iphone.

Я использую skpsmtpmessage http://code.google.com/p/skpsmtpmessage/, но при отправке почты в gmail отправляет тело сообщения в виде вложения.

спасибо.

1 Ответ

4 голосов
/ 11 декабря 2013

Попробуйте использовать https://github.com/MailCore/mailcore2. Он асинхронный и поддерживает большую часть почтового протокола.

Посмотрите пример отправки почты:

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