How to get mail configuration information if allowed? - ios

Hi I am using SMTP server framework to send mails.
NSArray *arr1 = [testMsg.fromEmail componentsSeparatedByString:#"#"];
NSArray *arr2 = [[arr1 objectAtIndex:1] componentsSeparatedByString:#"."];
if ([arr2 containsObject:#"gmail"]) {
testMsg.relayHost = #"smtp.gmail.com";
}
else if ([arr2 containsObject:#"yahoo"]) {
testMsg.relayHost = #"smtp.mail.yahoo.com";
}
else if ([arr2 containsObject:#"hotmail"] || [arr2 containsObject:#"live"]) {
testMsg.relayHost = #"smtp.live.com";
}
else
{
NSString *smtpRelay = [[NSString alloc]init];
smtpRelay = [NSString stringWithFormat:#"smtp.%#.com",[arr2 objectAtIndex:0]];
testMsg.relayHost = smtpRelay;
}
testMsg.requiresAuth = YES;
testMsg.login = #"mycompanyUserName#mycompany.com";
testMsg.password = #"********";
testMsg.subject = #"This is the email subject line";
testMsg.wantsSecure = YES; // smtp.gmail.com doesn't work without TLS!
If i want to send a mail from my office ID or other i want to fetch mail info automatically that is configured in MAIL application.
So That i can send a mail from configured mail (in device).is it possible to get the info like this ...if allowed ....please help me ......I don't want to user to enter id and password...Thanks in advance

Related

iOS PayUMoney SDK-key is not valid

I have integrate payumoney payment gateway. And I am able to create correct hash with the key, but at the end am getting an alert message as "key is not valid".what would be the problem?
Here is the code. I use the link "https://www.payumoney.com/payment-gateway-integration-guide.html" to download the payumoney SDK.
- (IBAction)startPaymentTapped:(id)sender {
[self setPaymentParameters];
//Start the payment flow
PUMMainVController *paymentVC = [[PUMMainVController alloc] init];
UINavigationController *paymentNavController = [[UINavigationController alloc] initWithRootViewController:paymentVC];
[self presentViewController:paymentNavController
animated:YES
completion:nil];
}
- (void)setPaymentParameters {
self.params = [PUMRequestParams sharedParams];
self.params.environment = PUMEnvironmentProduction;
self.params.amount = self.amount.text;
self.params.key = #"mykeyvalue";
self.params.merchantid = #"merchantid";
self.params.txnid = [self getRandomString:2];
self.params.surl = #"https://www.payumoney.com/mobileapp/payumoney/success.php";
self.params.furl = #"https://www.payumoney.com/mobileapp/payumoney/failure.php";
self.params.delegate = self;
self.params.firstname = self.firstname.text;
self.params.productinfo = self.productinfo.text;
self.params.email = self.email.text;
self.params.phone = #"";
self.params.udf1 = #"";
self.params.udf2 = #"";
self.params.udf3 = #"";
self.params.udf4 = #"";
self.params.udf5 = #"";
self.params.udf6 = #"";
self.params.udf7 = #"";
self.params.udf8 = #"";
self.params.udf9 = #"";
self.params.udf10 = #"";
self.params.hashValue = [self getHash];
}
- (NSString *)getRandomString:(NSInteger)length {
NSMutableString *returnString = [NSMutableString stringWithCapacity:length];
NSString *numbers = #"0123456789";
// First number cannot be 0
[returnString appendFormat:#"%C", [numbers characterAtIndex:(arc4random() % ([numbers length]-1))+1]];
for (int i = 1; i < length; i++) {
[returnString appendFormat:#"%C", [numbers characterAtIndex:arc4random() % [numbers length]]];
}
return returnString;
}
- (NSString*)getHash {
NSString *hashSequence = [NSString stringWithFormat:#"mykeyvalue|%#|%#|%#|%#|%#|||||||||||salt",self.params.txnid, self.params.amount, self.params.productinfo,self.params.firstname, self.params.email];
NSString *rawHash = [[self createSHA512:hashSequence] description];
NSString *hash = [[[rawHash stringByReplacingOccurrencesOfString:#"<" withString:#""]stringByReplacingOccurrencesOfString:#">" withString:#""]stringByReplacingOccurrencesOfString:#" " withString:#""];
return hash;
}
- (NSData *) createSHA512:(NSString *)source {
const char *s = [source cStringUsingEncoding:NSASCIIStringEncoding];
NSData *keyData = [NSData dataWithBytes:s length:strlen(s)];
uint8_t digest[CC_SHA512_DIGEST_LENGTH] = {0};
CC_SHA512(keyData.bytes, (CC_LONG)keyData.length, digest);
NSData *output = [NSData dataWithBytes:digest length:CC_SHA512_DIGEST_LENGTH];
NSLog(#"out --------- %#",output);
return output;
}
Please check data when you send payumoney for create hash key with server api data for create your hash key.
self.params.environment = PUMEnvironmentProduction;
Through the above code you can pay using net banking successfully. If you want to test
your payment gateway for dummy credit/debit card some changes are required. I am
listing it down. Try it.
Instead of
self.params.environment = PUMEnvironmentProduction; //write
self.params.environment = PUMEnvironmentTest;
change the urls as
self.params.surl = #"https://test.payumoney.com/mobileapp/payumoney/success.php";
self.params.furl = #"https://test.payumoney.com/mobileapp/payumoney/failure.php";
// We need test url for testing purpose.
Make sure you have activated your payumoney account by clicking on link that you got in mail.
Use the below dummy master card details
Test Card Name: any name
Test Card Number: 5123456789012346
Test CVV: 123
Test Expiry: May 2017

Yelp search Api in iOS

I am working on a app in which I have to show accessories, their price & other information from Yelp.
After a lot of searching I have found a useful link: https://github.com/Yelp/yelp-api/tree/master/v2/ios
But this method is not working for me.
Until now I have only used a single web service which is working & other's giving error like missing parameter.
This is working:
http://api.yelp.com/business_review_search?term=mobile&ywsid=PyHVqegFdleV******&tl_lat=37.9&tl_long=-122.5&br_lat=37.788022&br_long=-122.399797
Is there another API call which returns me the price , offers & other information because above one is for review.
Check my answer: How to search local business by name, location in iOS?
In success Venue block information about event
-(instancetype)initWithDict:(NSDictionary *)dict {
self = [super init];
if (self) {
self.name = [dict objectForKey:#"name"];
self.venueId = [dict objectForKey:#"id"];
self.thumbURL = [dict objectForKey:#"image_url"];
self.ratingURL = [dict objectForKey:#"rating_img_url"];
self.yelpURL = [dict objectForKey:#"url"];
self.venueId = [dict objectForKey:#"id"];
self.reviewsCount =[[dict objectForKey:#"review_count"] stringValue];
self.categories = [dict objectForKey:#"categories"][0][0];
self.distance = [dict objectForKey:#"distance"];
self.price = [dict objectForKey:#"deals.options.formatted_price"];
self.address = [[[dict objectForKey:#"location"] objectForKey:#"address"] componentsJoinedByString:#", "];
NSArray *adr = [[dict objectForKey:#"location"] objectForKey:#"display_address"];
self.displayAddress = [adr componentsJoinedByString:#","];
}
return self;
}

Not able to test the transaction using test account in Authorize.net

In iPhone simulator, i have registerd and also logged in successfully using authorize.net . But i am not able to perform transaction. Codes for MobileDeviceLoginRequest and createTransaction as in below.
-(void)loginToGateway
{
MobileDeviceLoginRequest *mobileDeviceLoginRequest = [MobileDeviceLoginRequest
mobileDeviceLoginRequest];
mobileDeviceLoginRequest.anetApiRequest.merchantAuthentication.name = #"***";
mobileDeviceLoginRequest.anetApiRequest.merchantAuthentication.password = #"*****";
mobileDeviceLoginRequest.anetApiRequest.merchantAuthentication.mobileDeviceId = [OpenUDID value];
[AuthNet authNetWithEnvironment:ENV_TEST];
AuthNet *an = [AuthNet getInstance];
[an setDelegate:self];
[an mobileDeviceLoginRequest:mobileDeviceLoginRequest];
}
-(void)mobileDeviceLoginSucceeded:(MobileDeviceLoginResponse *)response
{
sessionToken = [response.sessionToken retain];
[self createTransaction];
}
-(void)createTransaction
{
AuthNet *an = [AuthNet getInstance];
[an setDelegate:self];
CreditCardType *creditCardType = [CreditCardType creditCardType];
creditCardType.cardNumber = #"4111111111111111";
creditCardType.cardCode = #"100";
creditCardType.expirationDate = #"1212";
PaymentType *paymentType = [PaymentType paymentType];
paymentType.creditCard = creditCardType;
ExtendedAmountType *extendedAmountTypeTax = [ExtendedAmountType extendedAmountType];
extendedAmountTypeTax.amount = #"0";
extendedAmountTypeTax.name = #"Tax";
ExtendedAmountType *extendedAmountTypeShipping = [ExtendedAmountType extendedAmountType];
extendedAmountTypeShipping.amount = #"0";
extendedAmountTypeShipping.name = #"Shipping";
LineItemType *lineItem = [LineItemType lineItem];
lineItem.itemName = #"Soda";
lineItem.itemDescription = #"Soda";
lineItem.itemQuantity = #"1";
lineItem.itemPrice = #"1.00";
lineItem.itemID = #"1";
TransactionRequestType *requestType = [TransactionRequestType transactionRequest];
requestType.lineItems = [NSArray arrayWithObject:lineItem];
requestType.amount = #"1.00";
requestType.payment = paymentType;
requestType.tax = extendedAmountTypeTax;
requestType.shipping = extendedAmountTypeShipping;
CreateTransactionRequest *request = [CreateTransactionRequest createTransactionRequest];
request.transactionRequest = requestType;
request.transactionType = AUTH_ONLY;
request.anetApiRequest.merchantAuthentication.mobileDeviceId = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
request.anetApiRequest.merchantAuthentication.sessionToken = sessionToken;
[an purchaseWithRequest:request];}
mobileDeviceLoginResponse as in below: // i am getting session also
<resultCode>Ok</resultCode>
<message>
<code>I00001</code>
<text>Successful.</text>
createTransactionResponse as in below:
<code>E00054</code>
<text>The mobile device is not registered with this merchant account.</text>
Error code E00054 indicates you need to perform a mobileDeviceRegistrationRequest and approve the device in the merchant interface before you can create transactions.

Send HTML email with SKPSMTP iOS

I am trying to send an HTML email from my SKPSMTP code in iOS. Right now, I'm just sending plain text, but I'm trying to upgrade that a little. I've included that code below.
I can't find any documentation. How can I upload an HTML file and include that as it's body. Also, there's an image that's being loaded from the same directory as the HTML file, if that makes a difference in the answer. Thanks.
NSMutableString *emailBody = [NSMutableString stringWithFormat:#"Here's your code again, "];
[emailBody appendString:userCode];
SKPSMTPMessage *email = [[SKPSMTPMessage alloc] init];
email.fromEmail = #"me#gmail.com";
NSString *toEmail = [NSString stringWithFormat:#"%#", self.loginInput.text];
email.toEmail = toEmail;
email.relayHost = #"smtp.gmail.com";
email.requiresAuth = YES;
email.login = #"me#gmail.com";
email.pass = #"myPass";
email.subject = #"Your Validation Code";
email.wantsSecure = YES;
email.delegate = self;
NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:#"text/plain",kSKPSMTPPartContentTypeKey,
emailBody,kSKPSMTPPartMessageKey,#"8bit",kSKPSMTPPartContentTransferEncodingKey, nil];
email.parts = [NSArray arrayWithObjects:plainPart, nil];
// Send it!
[email send];
So, here's the answer I came across, just so everyone else can get the benefit of me struggling through:
//Send them an e-mail
NSError* error = nil;
NSString *path = [[NSBundle mainBundle] pathForResource: #"loginEmail" ofType: #"html"];
NSString *result = [NSString stringWithContentsOfFile: path encoding:
NSUTF8StringEncoding error: &error];
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:#"<!--INJECT CODE HERE -->"
options:0
error:&error];
NSString *emailBody = [regex stringByReplacingMatchesInString:result options:0 range:NSMakeRange(0, [result length]) withTemplate:code];
NSLog(#"%#", [emailBody class]);
SKPSMTPMessage *email = [[SKPSMTPMessage alloc] init];
email.fromEmail = #"myemail#gmail.com";
NSString *toEmail = [NSString stringWithFormat:#"%#", self.loginInput.text];
email.toEmail = toEmail;
email.relayHost = #"smtp.gmail.com";
email.requiresAuth = YES;
email.login = #"myemail#gmail.com";
email.pass = #"myPass"
email.subject = #"Your Validation Code";
email.wantsSecure = YES;
email.delegate = self;
NSDictionary *htmlPart = [NSDictionary dictionaryWithObjectsAndKeys:#"text/html",kSKPSMTPPartContentTypeKey, emailBody,kSKPSMTPPartMessageKey,#"8bit",kSKPSMTPPartContentTransferEncodingKey, nil];
email.parts = [NSArray arrayWithObjects:htmlPart, nil];
// Send it!
NSLog(#"ABOUT TO SEND");
[email send];
So, I had to write an HTML file, host all my images on tinypic to include in the HTML, write some text to regex switch out my code variable, load in it in here and attach it as the part of my email with key "text/html". This code works, but if anyone has any other suggestions that are helpful, I'm willing to mark them as the right answer!

Email attachment sent using SKPSMTPMessage appears in iOS mail client as contact

I have tested the code for sending attachments using this useful library:
Skpsmtpmessage library
The email seems to get sent correctly, and when I view it through hotmail or gmail clients I see the jpeg image. However, when I view this same email through an iOS mail client, the attachment appears as a "contact" and clicking on this gives me the option to save the file as a new contact.
I have tried sending an email with jpeg attachment from hotmail, and when I do this it appears correctly in the iOS client.
Does anyone know whether this is the code or iOS getting it wrong?
//the guts of the message.
SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];
testMsg.fromEmail = #"aname#gmail.com";
testMsg.toEmail = #"aname#gmail.com";
testMsg.relayHost = #"smtp.gmail.com";
testMsg.requiresAuth = YES;
testMsg.login = #"aname#gmail.com";
testMsg.pass = #"password";
testMsg.subject = #"The message subject";
testMsg.wantsSecure = YES; // smtp.gmail.com doesn't work without TLS!
// Only do this for self-signed certs!
// testMsg.validateSSLChain = NO;
testMsg.delegate = self;
//email contents
NSDate* now = [NSDate date];
NSString * bodyMessage = [NSString stringWithFormat:#"The message body"];
// email image if it exists
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents/file.jpeg"];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSMutableArray* parts = [[NSMutableArray alloc] init];
// add plain part
NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:#"text/plain",kSKPSMTPPartContentTypeKey,
bodyMessage ,kSKPSMTPPartMessageKey,#"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];
[parts addObject: plainPart];
// add attachments
NSData *attachmentData = [NSData dataWithContentsOfFile:jpgPath];
NSString *directory = #"text/directory;\r\n\tx-unix-mode=0644;\r\n\tname=\"file.jpeg\"";
NSString *attachment = #"attachment;\r\n\tfilename=\"file.jpeg\"";
NSDictionary *image_part = [NSDictionary dictionaryWithObjectsAndKeys:
directory,kSKPSMTPPartContentTypeKey,
attachment,kSKPSMTPPartContentDispositionKey,
[attachmentData encodeBase64ForData],kSKPSMTPPartMessageKey,
#"base64",kSKPSMTPPartContentTransferEncodingKey,nil];
[parts addObject: image_part];
testMsg.parts = parts;
[testMsg send];
Try to change
NSString *directory = #"text/directory;...
to
NSString *directory = #"text/jpeg;...
I hope this works for you!
Steffen

Resources