Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone to send email using smtp server?

in my application i am able to send email using smtp server,for that i have enter my correct email id and password. but when i enter my gmail or yahoo account details i am not able to send the mail. as i have set my relayHost = @"smtp.gmail.com"; then also i am not able to send the mail.

please help me out this.

following is my code :

-(void)sendEMAIL{

   SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];

    testMsg.fromEmail = str_uname;
    NSLog(@"str_Uname=%@",testMsg.fromEmail);

    testMsg.toEmail = str_info;

    NSLog(@"autoemail=%@",testMsg.toEmail);

    testMsg.relayHost = @"smtp.gmail.com";

    testMsg.requiresAuth = YES;

    testMsg.login = str_uname;
    NSLog(@"autoelogin=%@",testMsg.login);

    testMsg.pass = str_password;
    NSLog(@"autopass=%@",testMsg.pass);

   testMsg.subject = @"Schedule Sms And Email";

   testMsg.wantsSecure = YES; 

   NSString *sendmsg=[[NSString alloc]initWithFormat:@"%@",str_info2];
   NSLog(@"automsg=%@",sendmsg);

   testMsg.delegate = self;

   NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey,
                           sendmsg, kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];

    testMsg.parts = [NSArray arrayWithObjects:plainPart,nil];
    [testMsg send];
}

-(void)messageSent:(SKPSMTPMessage *)message{ 
   [message release];     
}

-(void)messageFailed:(SKPSMTPMessage *)message error:(NSError *)error{
   [message release];
}
like image 734
Nilesh .S. Joshi Avatar asked Nov 13 '22 04:11

Nilesh .S. Joshi


1 Answers

you can also source code from hear https://github.com/kailoa/iphone-smtp Its a awesome code using smtp server.

http://iphonesdksnippets.com/send-email-with-attachments-on-iphone.html use this link is also good....Just download framework from there and use that code.Its nice too.

like image 158
sinh99 Avatar answered Nov 16 '22 04:11

sinh99