我需要在后台发送电子邮件,所以我必须使用名为:SMTP的库。我使用的主要类是:SKPSMTPMessage。问题是“ccEmail”,当我添加2个以上的收件人时,它无法发送电子邮件。 (这需要很长的时间来委托方法)。它适用于收件人< = 2。
smtpEmail.ccEmail = @"xyz@gmail.com, xyz1@gmail.com, xyz2@gmail.com";
任何人都知道这一点,请帮助我。非常感谢你!
答案 0 :(得分:8)
parseBuffer函数有我的更改:
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;
}
并将其添加到标题中:
NSMutableArray *multipleRcptTo;
编辑:同时更改以下方法,因为multipleRcptTo
用作NSMutableString,这是本地声明:
- (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
一次性发送到SMTP地址,并且必须逐个发送。