Reputation: 1838
A strange behaviour is happening when I am trying to send mail from device.
I have used SMTP to send mail from background in my app and I have to send user's current location URL in app.
Now, when I send it from simulator it works almost fine and i got this url -
https://maps.google.com/maps?f=q&q=0.000000,0.000000
But, when I send it from device it sends the url like this -
https://maps.google.com/maps?f=q&q".719793,75.877068
The code I used to make url is
-(NSString*)LocationLinkTosentInMail
{
CLLocationCoordinate2D coordinate = [self getLocation];
NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];
NSLog(@"*dLatitude : %@", latitude);
NSLog(@"*dLongitude : %@",longitude);
NSString *currentLocationURL = [NSString stringWithFormat:@"https://maps.google.com/maps?f=q&q=%@,%@",latitude,longitude];
return currentLocationURL;
}
NSURL *locationURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@",[self LocationLinkTosentInMail]]];
In SMTP mail function, I use this code to make dictionary
NSDictionary *plain_text_part = [NSDictionary dictionaryWithObjectsAndKeys:
@"text/plain\r\n\tcharset=UTF-8;\r\n\tformat=flowed", kSKPSMTPPartContentTypeKey,
[NSString stringWithFormat:@"My Location is: %@",locationURL], kSKPSMTPPartMessageKey,
@"quoted-printable", kSKPSMTPPartContentTransferEncodingKey,
nil];
Can anyone suggest me if any change required in code?
Why simulator and device are showing different behavior to send this url?
Upvotes: 0
Views: 102
Reputation: 1838
Whenever we have to send URL
thourgh smtp
in objective c, we should always careful about the special character of url.
Finally i got the solution of my problem in the encoding process
.
the Encoding in the NSDictionary
object, I changed it from quoted-printable
to 8bit
.
Now dictionary
obj would be:
NSDictionary *plain_text_part = [NSDictionary dictionaryWithObjectsAndKeys:
@"text/plain", kSKPSMTPPartContentTypeKey,
strMessage, kSKPSMTPPartMessageKey,
@"8bit", kSKPSMTPPartContentTransferEncodingKey,
nil];
Upvotes: 0
Reputation: 2987
Use HTML Tag and in mail body enable HTML in iOS
[emailDialog setMessageBody:mailBody isHTML:YES];
Upvotes: 1