Sending email to 2 recipients using SKPSMTPMessage - iphone

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

Related

Line Chart - Display xAxis at bottom

I've looked everywhere and tried various approaches and cannot figure this out.
How do I position the xAxis at the bottom of the line chart?
In viewDidLoad:
[self initChartProperties];
[self updateChartData:5];
initChartProperties:
- (void)initChartProperties2 {
_chartView.delegate = self;
_chartView.descriptionText = #"";
_chartView.noDataTextDescription = #"You need to provide data for the chart.";
_chartView.dragEnabled = YES;
_chartView.pinchZoomEnabled = YES;
_chartView.legend.enabled = NO;
[_chartView setScaleEnabled:YES];
_chartView.leftAxis.customAxisMax = 21;
_chartView.leftAxis.customAxisMin = 0;
_chartView.leftAxis.drawZeroLineEnabled = NO;
_chartView.leftAxis.enabled = YES;
_chartView.xAxis.axisLineWidth = 2.0f;
_chartView.xAxis.drawAxisLineEnabled = YES;
_chartView.rightAxis.enabled = NO;
[_chartView.viewPortHandler setMaximumScaleY: 2.f];
[_chartView.viewPortHandler setMaximumScaleX: 2.f];
}
updateChartData:
- (void)updateChartData:(int)count {
NSMutableArray *xVals = [[NSMutableArray alloc] init];
NSMutableArray *yVals = [[NSMutableArray alloc] init];
for (int i = 0; i < count; i++) {
[xVals addObject:[#(i) stringValue]];
}
for (int i = 0; i < count; i++) {
[yVals addObject:[[ChartDataEntry alloc] initWithValue:i xIndex:i]];
}
LineChartDataSet *set1 = [[LineChartDataSet alloc] initWithYVals:yVals label:#""];
set1.lineWidth = 1.0;
set1.circleRadius = 0.0;
set1.drawCircleHoleEnabled = NO;
set1.valueFont = [UIFont fontWithName:#"HelveticaNeue-Light" size:9.0f];
NSMutableArray *dataSets = [[NSMutableArray alloc] init];
[dataSets addObject:set1];
LineChartData *data = [[LineChartData alloc] initWithXVals:xVals dataSets:dataSets];
_chartView.data = data;
}
Result:
line graph
I just want the xAxis values to be rendered at the bottom of the graph, not the top.
Sorry for the seemingly simple question.
Appreciate any help.
Nevermind - finally figured it out
_chartView.xAxis.labelPosition = XAxisLabelPositionBottom;
In the most recent version (currently 3.0) you can do it with
_chartView.xAxis.labelPosition = XAxis.LabelPosition.bottom

UIActivityViewController - Detecting error in sending vs. cancel

Currently I'm using the following code to instantiate a UIActivityViewController:
NSArray *itemsToShare = [[NSArray alloc] initWithObjects:bodyMessage, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = [[NSArray alloc] initWithObjects: UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypePostToWeibo,UIActivityTypePostToFacebook,UIActivityTypePostToTwitter, nil];
[activityVC setValue:subject forKey:#"subject"];
[self presentViewController:activityVC animated:YES completion:nil];
[activityVC setCompletionHandler:^(NSString *activityType, BOOL done)
{
NSString *ServiceType;
if ( [activityType isEqualToString:UIActivityTypeMail] ) ServiceType = #"Mail.";
if ( [activityType isEqualToString:UIActivityTypeMessage] ) ServiceType = #"Messenger.";
NSMutableString *shareWithActivityResultMessage;
NSString *alertTitle;
if (done)
{
alertTitle = #"Success!";
shareWithActivityResultMessage = [NSMutableString stringWithString:successMessage];
[shareWithActivityResultMessage appendString:ServiceType];
}
else
{
// didn't succeed.
alertTitle = #"Error";
shareWithActivityResultMessage = [NSMutableString stringWithString:errorMessage];
}
When I cancel composing, the ActivityVC done = false and thus the error message is triggered. Is there a way to detect canceling as opposed to an actual error in sending the message?
You can using the new UIActivityViewControllerCompletionWithItemsHandler type in iOS 8:
activityVC.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError){
...
}
Just check the activityError property

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//";

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

Wierd behaviour of a singleton object

I'm having really weird situation. I create a singletone object of a class named "Profile like this:
static Profile *currentProfile;
+ (Profile *)currentProfile
{
#synchronized(self)
{
if (currentProfile == nil)
currentProfile = [[Profile alloc] init];
}
return currentProfile;
}
- (id)init
{
self = [super init];
if (self)
{
// Initialization code here.
isChecked = [[[NSUserDefaults standardUserDefaults] objectForKey:#"isChecked"] boolValue];
if (isChecked)
{
NSLog(#"isChecked block is called");
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:#"myEncodedObjectKey"];
self = (Profile *) [NSKeyedUnarchiver unarchiveObjectWithData:data];
[self retain];
for (int i = 0; i < self.avatar.count; i++)
[self.avatar replaceObjectAtIndex:i withObject:[UIImage imageWithData:[self.avatar objectAtIndex:i]]];
}
else
{
password = #"";
pfefferID = #"";
email = #"";
avatar = [[NSMutableArray alloc] initWithObjects:
[UIImage imageNamed:#"empty_image.png"],
[UIImage imageNamed:#"empty_image.png"],
[UIImage imageNamed:#"empty_image.png"],
[UIImage imageNamed:#"empty_image.png"],
[UIImage imageNamed:#"empty_image.png"],nil];
isBoy = YES;
friends = [[NSMutableDictionary alloc] init];
rating = 0;
}
}
return self;
}
In init method i check a certain condition stored in NSUserDefaults by using BOOL variable named "isChecked". isChecked is equal to YES and everything works fine. But... i create this Profile object in AppDelegate file like this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
users = [[NSMutableDictionary alloc] init];
usersForLeaderboardFromServer = [[NSMutableDictionary alloc] init];
listOfFriendsFromServer = [[NSMutableDictionary alloc] init];
currentProfile = [Profile currentProfile];
sessionID = 0;
if (!currentProfile.isChecked)//why????
NSLog(#"not checked");
if (currentProfile.isChecked)
{
[self getUsersForLeaderboardFromServer];
MainMenuView *mainMenu = [[[MainMenuView alloc] init] autorelease];
[self.navigationController pushViewController:mainMenu animated:YES];
}
}
So the same isChecked variable which a moment (far less than a moment actually) ago was equal to YES gets equal to NO when being used in application didFinishLaunchingWithOptions method by accessing it via dot. What's going on? I'm able to handle it but i'm just curious about this situation. Do you know what's wrong with it?
You're reassigning self in init, so you're returning the new object rather than the one you set isChecked on. See this code:
self = (Profile *) [NSKeyedUnarchiver unarchiveObjectWithData:data];
[self retain];
It's slightly awkward to do things like you've got - I would certainly not recommend replacing it in the way you have. For a start, the value you set to the static currentProfile is not being updated when you reassign self so that's still the old one. And also you're not releasing the old self when you reassign.
To fix it you could do something like this:
id newSelf = (Profile *) [NSKeyedUnarchiver unarchiveObjectWithData:data];
newSelf.isChecked = isChecked;
[self release];
self = [newSelf retain];
But I don't really advocate that personally. I suggest you load in the object from your archive and then proceed to update yourself with it rather than reassigning self.