1

I used SKPSMTPMessage in my iPhone application. Problem is with multiple recipients. I just need to send email to two recipient.

I'm using the following code:

-(void)sendEmail {

// create soft wait overlay so the user knows whats going on in the background.
[self createWaitOverlay];

//the guts of the message.
SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];
testMsg.fromEmail = @"support@dsfaes.co.uk";
//  testMsg.toEmail = phone;
testMsg.toEmail=@"manjinderr@gmail.com;

testMsg.relayHost = @"smtp.nman.co.uk";
testMsg.requiresAuth = YES;
testMsg.login = @"support@man.co.uk";
testMsg.pass = @"nfsdxsdfswdrt";
testMsg.subject = @"The Confirmation";
testMsg.wantsSecure = YES; // smtp.gmail.com doesn't work without TLS!

// Only do this for self-signed certs!
// testMsg.validateSSLChain = NO;
testMsg.delegate = self;
}

Anyone knows how can i send email to 2 recipient

ChikabuZ
  • 10,031
  • 5
  • 63
  • 86
Mann
  • 5,477
  • 6
  • 45
  • 57

1 Answers1

3

There is the heck solution for this

First Create the recipientsArray which contains your recipients

NSArray* recipientsArray = [NSArray arrayWithObjects:@"abc@abc.com",@"xyz@xyz.com",nil];

Call you sendEmail method

for(NSString* toEmailAddress in recipientsArray){
   [self sendEmail:toEmailAddress];
}

Then define your sendEmail method:

-(void)sendEmail:(NSString*)_toEmailAddress {
    // create soft wait overlay so the user knows whats going on in the background.
    [self createWaitOverlay];

    //the guts of the message.
    SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];
    testMsg.fromEmail = @"support@dsfaes.co.uk";

    testMsg.toEmail = _toEmailAddress;
    testMsg.relayHost = @"smtp.nman.co.uk";
    testMsg.requiresAuth = YES;
    testMsg.login = @"support@man.co.uk";
    testMsg.pass = @"nfsdxsdfswdrt";
    testMsg.subject = @"The Confirmation";
    testMsg.wantsSecure = YES; // smtp.gmail.com doesn't work without TLS!

    // Only do this for self-signed certs!
  // testMsg.validateSSLChain = NO;
  testMsg.delegate = self;
}
Praveen-K
  • 3,401
  • 1
  • 23
  • 31
  • I will try and let you know:-) – Mann Aug 13 '11 at 21:27
  • Ok @Manjinder S, and is your earlier problem solved? location one(ggogleurl ? – Praveen-K Aug 13 '11 at 21:29
  • Where should i put recipientsArray=[@"abc@abc,com,@"dfa.com""]; and for loop? in sendEmail: method? – Mann Aug 13 '11 at 21:29
  • No Mr. Parveen. not yet. let me try this first then i tell you about that, – Mann Aug 13 '11 at 21:30
  • @Manjinder S wherever you were calling your sendEmail method earlier. when you were calling sendEmail method before ? for example **lets assume** you were calling in viewDidLoad or on any button action there you just call like recipientsArray = [@"abc@abc.com",@"xyz@xyz.com"]; for(NSString* toEmailAddress in recipientsArray){ [self sendEmail:toEmailAddress]; } – Praveen-K Aug 13 '11 at 21:33
  • Yes i was calling it in button action. but it shows error at [@"abc@abc.com",@"xyz@xyz.com"]; says use of undeclared recpientArray – Mann Aug 13 '11 at 21:35
  • @Manjinder S you seriously need to learn objC seriously, if it say recpientArray is undeclared it means you need to declare it. ok wait i edit my answer to **solve your error. ** – Praveen-K Aug 13 '11 at 21:37
  • yah i declared it using NSArray *recepientArray – Mann Aug 13 '11 at 21:39
  • It shows warning then i used NSArray *recipientsArray = [[NSArray alloc] initWithObjects:@"manjinderdfdr@gmail.com",@"maddfar@hotmail.co.uk",nil]; – Mann Aug 13 '11 at 21:40
  • Now it says use of undeclared identifier '_toEmailAddress' infront of testMsg.toEmail = _toEmailAddress; – Mann Aug 13 '11 at 21:41
  • Mr. Control V i have sent u mail on gmail. please have a look if u get time. n reply. thanks – Mann Aug 17 '11 at 14:16