Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send email to multiple recipients with SKPSMTPMessage?

Tags:

objective-c

I need to send email in background, so I have to use the library named: SMTP. And the main class I used is: SKPSMTPMessage. The problem is "ccEmail", when I add more than 2 recipients, it can't send email. (that takes too long time to go to delegate methods). It works well with recipient <= 2.

smtpEmail.ccEmail = @"[email protected], [email protected], [email protected]";   

Anyone knows this, please help me. Thanks you so much !

like image 955
abelhoang Avatar asked Apr 27 '11 03:04

abelhoang


People also ask

How do I send a message to multiple recipients?

If you have a multiple recipient list, you can separate each address with a comma, semicolon, space or by pressing the enter key. Now, compose your new message and then select the Message tab and click the Send button.

How do I send an email to multiple email addresses?

In the Bcc field, start entering the email addresses you want to send the email to. Select email addresses from the drop-down list that appears when you start typing, or type in new email addresses. Separate each email address with a comma and a space. Compose your email and click on the blue send button at the bottom of the screen.

What happens if you send the same email to multiple recipients?

Normally, when you send the same email to multiple recipients, all addresses of the recipients are visible to everyone receiving the email. But if the recipients don’t know each other, this may be not a good idea. In this case, you should keep the recipients from seeing each other's email addresses.

How do I send an email without the recipient knowing?

If you’re using Yahoo Mail, sending an email to multiple recipients without them knowing involves a similar process as on Gmail. Start by clicking on the blue “Compose” button in the top-left corner of your screen. You will see the Cc/Bcc option in the top-right corner of your email editor, as in this screenshot:


1 Answers

There is my changes in the parseBuffer function:

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 into header:

NSMutableArray *multipleRcptTo;

EDIT : Also change below method as multipleRcptTo is used as NSMutableString which is 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 to the SMTP address all at once, and must send one by one.

like image 74
Maxim Avatar answered Sep 28 '22 07:09

Maxim