iphone to send email using smtp server? - iphone

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];
}

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.

you can manage relay host for yahoo, gmail, hotmail etc. in this way-
NSArray *arr1 = [fromEmail componentsSeparatedByString:#"#"];
NSArray *arr2 = [[arr1 objectAtIndex:1] componentsSeparatedByString:#"."];
if ([arr2 containsObject:#"gmail"]) {
smtp_message.relayHost = #"smtp.gmail.com";
}
else if ([arr2 containsObject:#"yahoo"]) {
smtp_message.relayHost = #"smtp.mail.yahoo.com";
}
else if ([arr2 containsObject:#"hotmail"] || [arr2 containsObject:#"live"]) {
smtp_message.relayHost = #"smtp.live.com";
}
else
{
NSString *smtpRelay = [[NSString alloc]init];
smtpRelay = [NSString stringWithFormat:#"smtp.%#.com",[arr2 objectAtIndex:0]];
smtp_message.relayHost = smtpRelay;
}

Related

Use of undeclared identifier PhonesViewController ios7 xCode

Can you please help me with this error that I'am getting...
Basically, I'm trying to import all my contact list from my address book. Also I'm checking the phone number label, but the error that I'm getting is "Use of undeclared identifier PhonesViewController ios7 xCode" and I have that viewController, and also I have added the class in storyboard for the viewcontroller although I think that it is not necessary
Thanks in advance
Here is my code:
#import "PhonesViewController.h"
#implementation PhonesViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
- (BOOL)PhohesViewController: (ABPeoplePickerNavigationController *)picker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
// Name of contact.
NSString* name = (NSString *)ABRecordCopyCompositeName(person);
// Numbers of selected contact
ABMutableMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSMutableString *mobile = [[NSMutableString alloc] init];
NSMutableString *office = [[NSMutableString alloc] init];
// Getting if Mobile, Office(work) numbers exist
for(CFIndex numberIndex = 0; numberIndex < ABMultiValueGetCount(phones); numberIndex++)
{
// Number in contact details of current index
CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(phones, numberIndex);
// Label of Phone Number
CFStringRef locLabel = ABMultiValueCopyLabelAtIndex(phones, numberIndex);
NSString *phoneLabel =(NSString*) ABAddressBookCopyLocalizedLabel(locLabel);
// Phone number
NSString *phoneNumber = (NSString *)phoneNumberRef;
// Release Phone Number and locationLabel reference object
CFRelease(phoneNumberRef);
CFRelease(locLabel);
NSLog(#" - %# (%#)", phoneNumber, phoneLabel);
if ([phoneLabel isEqualToString:#"mobile"])// Mobile number saving.
{
[mobile appendFormat:#"%#", phoneNumber];
}
else if ([phoneLabel isEqualToString:#"work"])// Office number saving.
{
[office appendFormat:#"%#", phoneNumber];
}
[phoneNumber release];
}
CFRelease(phones);
// Emails of selected contact
ABMutableMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
NSMutableString *generalMail = [[NSMutableString alloc] init];
NSMutableString *officeMail = [[NSMutableString alloc] init];
// Getting if Home, Office(work) mails exist
for(CFIndex numberIndex = 0; numberIndex < ABMultiValueGetCount(emails); numberIndex++)
{
// Mail in contact details of current index
CFStringRef mailRef = ABMultiValueCopyValueAtIndex(emails, numberIndex);
// Label of Phone Number
CFStringRef locLabel = ABMultiValueCopyLabelAtIndex(emails, numberIndex);
NSString *mailLabel =(NSString*) ABAddressBookCopyLocalizedLabel(locLabel);
// Phone number
NSString *mail = (NSString *)mailRef;
// Release Phone Number and locationLabel reference object
CFRelease(mailRef);
CFRelease(locLabel);
NSLog(#" - %# (%#)", mail, mailLabel);
if ([mailLabel isEqualToString:#"mobile"])// Home mail.
{
[generalMail appendFormat:#"%#", mail];
}
else if ([mailLabel isEqualToString:#"work"])// Office(Work) mail.
{
[officeMail appendFormat:#"%#", mail];
}
[mail release];
}
CFRelease(emails);
[mobile release];
[office release];
[generalMail release];
[officeMail release];
[self dismissViewControllerAnimated:YES completion:nil];
return NO;
}
}
#end
Looks like a typo to me.
// Phohes?
- (BOOL)PhohesViewController: (ABPeoplePickerNavigationController *)picker //Phohes? shouldContinueAfterSelectingPerson:(ABRecordRef)person
Looking at your code and the image you've posted, you're defining a method within a method, you can't do that.

GData Objective-C Client Contact Service

I downloaded the last GData client via SVN https://code.google.com/p/gdata-objectivec-client/
I succesfully compiled it and I integrated successfully the static library inside my project.
I need to retrieve all gmail contacts about a google username:
- (GDataServiceGoogleContact *)contactService {
static GDataServiceGoogleContact* service = nil;
if (!service) {
service = [[GDataServiceGoogleContact alloc] init];
[service setShouldCacheResponseData:YES];
[service setServiceShouldFollowNextLinks:YES];
}
// update the username/password each time the service is requested
NSString *username = usr.text;
NSString *password = psw.text;
[service setUserCredentialsWithUsername:username
password:password];
return service;
}
- (IBAction)getContacts:(id)sender; {
GDataServiceGoogleContact *gc =[self contactService];
NSURL *feedURL = [GDataServiceGoogleContact contactFeedURLForUserID:usr.text];
GDataServiceTicket *ticket;
ticket = [gc fetchFeedWithURL:feedURL
delegate:self
didFinishSelector:#selector(ticket:finishedWithFeed:error:)];
[self startLoading];
}
The callback selector looks like this:
- (void)ticket:(GDataServiceTicket *)ticket finishedWithFeed:(GDataFeedContact *)feed
error:(NSError *)error {
[self stopLoading];
if (error == nil) {
NSArray *entries = [NSArray arrayWithArray:[feed entries]];
if ([entries count] > 0) {
for (GDataEntryContact *firstContact in entries) {
NSString *name = [((GDataNameElement*)[[firstContact name] fullName]) stringValue];
NSString *email = ([firstContact emailAddresses] != nil && [[firstContact emailAddresses] count]!=0) ? [[[firstContact emailAddresses] objectAtIndex:0] stringValueForAttribute:#"address"]: NSLocalizedString(#"not found",#"");
if (name == nil) {
name = email;
}
BBGmailContact *tmpContact = [[BBGmailContact alloc] initWithName:name email:email];
[contacts addObject:tmpContact];
[self.navigationController popViewControllerAnimated:YES];
}
[gmailDelegate contactsDidDownload:contacts];
} else {
[self createAlertView:NSLocalizedString(#"Warning", #"") message:NSLocalizedString(#"No contact found", #"")];
}
} else {
[self createAlertView:NSLocalizedString(#"Error", #"Error") message:NSLocalizedString(#"Please, check your user and password", #"")];
}
}
Why is every entry of entries a kind of class: GDataEntryBase instead GDataEntryContact?
Where is my error? Can someone help me?
Entries are created as GDataEntryBase if the application does not have the service-specific classes for Contacts compiled and linked into the app.
Be sure too that the appropriate build flags for the Contacts service are specified as described in the docs.

Error while sending email in iOS 5

I m using SKPSMTPMessage files to send the mails but it is showing the following error while sending the email
Error Domain=SKPSMTPMessageError
Code=535 "Invalid username or password."
UserInfo=0xaa2de20 {NSLocalizedRecoverySuggestion=Go to Email Preferences in the application and re-enter your username and password.,
NSLocalizedDescription=Invalid username or password.}
Where should I change the user name and password? The code is as follows:
SKPSMTPMessage *msg = [[SKPSMTPMessage alloc] init];
msg.fromEmail = #"123456789s#gmail.com";
msg.toEmail = to;
msg.relayHost = #"smtp.gmail.com";
msg.requiresAuth = YES;
msg.login = #"123456789#gmail.com";
msg.pass = #"123456789//";
msg.wantsSecure = YES; // smtp.gmail.com doesn't work without TLS!
msg.subject = [NSString stringWithFormat:#"Check Out %# by Docstoc", self.navigationItem.title];
msg.delegate = self;
NSMutableArray *msg_parts = [NSMutableArray array];
NSDictionary *plain_text_part = [NSDictionary dictionaryWithObjectsAndKeys:
#"text/html\r\n\tcharset=UTF-8;\r\n\tformat=flowed", kSKPSMTPPartContentTypeKey,
[message stringByAppendingString:#"\n"], kSKPSMTPPartMessageKey,
nil];
[msg_parts addObject:plain_text_part];
msg.parts = msg_parts;
[msg send];
Note: This is perfectly working code. Since last week it is showing the error.
try
NSMutableArray *msg_parts = [[NSMutableArray alloc]initWithArray:array];
instead of NSMutableArray *msg_parts = [NSMutableArray array];
Please check your below details are valid or not,
msg.login = #"123456789#gmail.com";
msg.pass = #"123456789//";

How to get user's email id of google account?

I am working on an iPhone app in which I am giving user option to login with his/her google account. Now, I want that user's google email id through JSON or XML. I have searched a lot, but did not satisfactory result.
Thanx in advance.
did you check the oauth autorization with google api at their developers site?
https://developers.google.com/accounts/docs/OAuth2
i think you can find something from this link.....
hope this link help you.....
http://code.google.com/p/gdata-objectivec-client/wiki/GDataObjCIntroduction
and
also https://code.google.com/p/gdata-objectivec-client/
:)
write bellow code when you want to get contact....
GDataServiceGoogleContact *service = [self contactService];
GDataServiceTicket *ticket;
BOOL shouldShowDeleted = TRUE;
const int kBuncha = 2000;
NSURL *feedURL = [GDataServiceGoogleContact contactFeedURLForUserID:kGDataServiceDefaultUser];
GDataQueryContact *query = [GDataQueryContact contactQueryWithFeedURL:feedURL];
[query setShouldShowDeleted:shouldShowDeleted];
[query setMaxResults:kBuncha];
ticket = [service fetchFeedWithQuery:query
delegate:self
didFinishSelector:#selector(contactsFetchTicket:finishedWithFeed:error:)];
[self setContactFetchTicket:ticket];
bellow method is GmailAPI delegate method...
- (GDataServiceGoogleContact *)contactService
{
static GDataServiceGoogleContact* service = nil;
if (!service) {
service = [[GDataServiceGoogleContact alloc] init];
[service setShouldCacheResponseData:YES];
[service setServiceShouldFollowNextLinks:YES];
}
[service setUserCredentialsWithUsername:txtEmail.text
password:txtPass.text];
return service;
}
after that you can get contact with bellow code...
for (int i = 0; i < [contacts count]; i++) {
GDataEntryContact *contact = [contacts objectAtIndex:i];
// NSLog(#">>>>>>>>>>>>>>>> elementname contact :%#", [[[contact name] fullName] contentStringValue]);
NSString *ContactName = [[[contact name] fullName] contentStringValue];
GDataEmail *email = [[contact emailAddresses] objectAtIndex:0];
// NSLog(#">>>>>>>>>>>>>>>> Contact's email id :%# contact name :%#", [email address], ContactName);
NSString *ContactEmail = [email address];
}
hope this help you....
:)

Sending email to 2 recipients using SKPSMTPMessage

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
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;
}