Send mail to multiple recipients using SKPSMTPMessage?

I need to send an email in the background, so I need to use a library named: SMTP. And the main class that I used is: SKPSMTPMessage. The problem is "ccEmail", when I add more than two recipients, it cannot send email. (it takes too much time to move on to delegation methods). It works well with the recipient <= 2.

smtpEmail.ccEmail = @" xyz@gmail.com , xyz1@gmail.com , xyz2@gmail.com "; 

Does anyone know this, please help me. Thank you very much!

+4
source share
1 answer

The parseBuffer function has my changes:

 case kSKPSMTPWaitingFromReply: { if ([tmpLine hasPrefix:@"250 "]) { if (!multipleRcptTo) { NSMutableString *multipleRcptToString = [NSMutableString string]; [multipleRcptToString appendString:[self formatAddresses:toEmail]]; [multipleRcptToString appendString:[self formatAddresses:ccEmail]]; [multipleRcptToString appendString:[self formatAddresses:bccEmail]]; multipleRcptTo = [[multipleRcptToString componentsSeparatedByString:@"\r\n"] mutableCopy]; [multipleRcptTo removeLastObject]; } if ([multipleRcptTo count] > 0) { NSString *rcptTo = [NSString stringWithFormat:@"%@\r\n", [multipleRcptTo objectAtIndex:0]]; [multipleRcptTo removeObjectAtIndex:0]; //DEBUGLOG(@"C: %@", rcptTo); if (CFWriteStreamWriteFully((CFWriteStreamRef)outputStream, (const uint8_t *)[rcptTo UTF8String], [rcptTo lengthOfBytesUsingEncoding:NSUTF8StringEncoding]) < 0) { error = [outputStream streamError]; encounteredError = YES; } else { [self startShortWatchdog]; } } if ([multipleRcptTo count] == 0) { sendState = kSKPSMTPWaitingToReply; } } break; } 

and add this to the header:

 NSMutableArray *multipleRcptTo; 

EDIT . Also change the method below, since multipleRcptTo used as NSMutableString, which is a local declaration:

 - (NSString *)formatAddresses:(NSString *)addresses { NSCharacterSet *splitSet = [NSCharacterSet characterSetWithCharactersInString:@";,"]; NSMutableString *multipleRcpt = [NSMutableString string]; if ((addresses != nil) && (![addresses isEqualToString:@""])) { if( [addresses rangeOfString:@";"].location != NSNotFound || [addresses rangeOfString:@","].location != NSNotFound ) { NSArray *addressParts = [addresses componentsSeparatedByCharactersInSet:splitSet]; for( NSString *address in addressParts ) { [multipleRcpt appendString:[self formatAnAddress:address]]; } } else { [multipleRcpt appendString:[self formatAnAddress:addresses]]; } } return(multipleRcpt); } 

SKPSMTPMessage sends SKPSMTPMessage to the SMTP address at once and must send one at a time.

+7
source

All Articles