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

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

Related

WeChat iOS SDK Sharing - missing description despite filling parameter

When I try to send link or picture with description paremeter to WeChatMoments or WeChatSession, description is never shown. Every other parameter is shown correctly, except description. There are no errors either. Here goes my code, notice that description is filled:
WXMediaMessage *message = [WXMediaMessage message];
message.title = #"Perfect Title";
message.description = #"Amazing Graphic";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithUTF8String:thumbnailPath]];
[message setThumbImage:[UIImage imageWithContentsOfFile:path]];
WXImageObject *ext = [WXImageObject object];
NSString* filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithUTF8String:contentPath]];
ext.imageData = [NSData dataWithContentsOfFile:filePath] ;
message.mediaObject = ext;
SendMessageToWXReq* req = [[[SendMessageToWXReq alloc] init]autorelease];
req.bText = NO;
req.message = message;
req.scene = (true)?WXSceneTimeline:WXSceneSession;
[WXApi sendReq:req];
I've tried code samples from WeChatDeveloper documentation, and even despite of filling description paremeter, it does only show link with title/graphic.
My question is, anybody faced same problem and there is any solution for missing description field?
May problem occur because my app is not yet verified?

How to get mail configuration information if allowed?

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

How to upload video on YouTube form ios app? By Using Oauth2 and YouTube GDATA classes

I am working on app in which user can upload video to YouTube. All working fine until I move my login feature from the client login to oauth2.
Now I can successfully authorize user and get ACCESS TOKEN, but I don't know how to use this ACCESS TOKEN to upload video in GDATA API methods.
in GDATA i am using some methodswhich use username and password. but now i dotn have username and password all i have is access_token
- (void)uploadVideoFile :(GTMOAuth2Authentication*)auth{
[mTitleField setText: [shareVidTitleArr objectAtIndex:0]];
[mDescriptionField setText: [shareVidDescpArr objectAtIndex:0]];
[mKeywordsField setText: #"Hi"];
[mCategoryField setText: #"Entertainment"];
NSString *devKey = [mDeveloperKeyField text];
GDataServiceGoogleYouTube *service = [self youTubeService];
[service setYouTubeDeveloperKey:devKey];
NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:kGDataServiceDefaultUser];
// NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:clientID];
// load the file data
NSArray *searchPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString *docDir = [searchPath objectAtIndex:0];
NSString *path = [docDir stringByAppendingPathComponent:[shareVidArr objectAtIndex:0]];
NSData *data = [NSData dataWithContentsOfFile:path];
NSString *filename = [path lastPathComponent];
NSLog(#"%#",filename);
// gather all the metadata needed for the mediaGroup
NSString *titleStr = [mTitleField text];
GDataMediaTitle *title = [GDataMediaTitle textConstructWithString:titleStr];
NSString *categoryStr = [mCategoryField text];
GDataMediaCategory *category = [GDataMediaCategory mediaCategoryWithString:categoryStr];
[category setScheme:kGDataSchemeYouTubeCategory];
NSString *descStr = [mDescriptionField text];
GDataMediaDescription *desc = [GDataMediaDescription textConstructWithString:descStr];
NSString *keywordsStr = [mKeywordsField text];
GDataMediaKeywords *keywords = [GDataMediaKeywords keywordsWithString:keywordsStr];
BOOL isPrivate = mIsPrivate;
GDataYouTubeMediaGroup *mediaGroup = [GDataYouTubeMediaGroup mediaGroup];
[mediaGroup setMediaTitle:title];
[mediaGroup setMediaDescription:desc];
[mediaGroup addMediaCategory:category];
[mediaGroup setMediaKeywords:keywords];
[mediaGroup setIsPrivate:isPrivate];
//[mediaGroup setProperty:filename forKey:#"vidID"];
NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:path
defaultMIMEType:#"video/quicktime"];
// create the upload entry with the mediaGroup and the file data
GDataEntryYouTubeUpload *entry;
entry = [GDataEntryYouTubeUpload uploadEntryWithMediaGroup:mediaGroup
data:data
MIMEType:mimeType
slug:filename];
SEL progressSel = #selector(ticket:hasDeliveredByteCount:ofTotalByteCount:);
[service setServiceUploadProgressSelector:progressSel];
GDataServiceTicket *ticket;
ticket = [service fetchEntryByInsertingEntry:entry
forFeedURL:url
delegate:self
didFinishSelector:#selector(uploadTicket:finishedWithEntry:error:)];
[self setUploadTicket:ticket];
}
Here's the complete example: https://github.com/youtube/yt-direct-lite-iOS/blob/master/YouTube%20Direct%20Lite%20for%20iOS/YouTubeUploadVideo.m
It uses Data API v3, which is the new API, GData will be deprecated really soon.
1)urinieto.com/iPhone/YouTubeTest.zip
2)then add your devkey and client id
3)remove gdata folder instead add GData-iOS-Static-Library-1.12-master
4)
//[service setShouldCacheDatedData:YES]; need to comment this line
[service setServiceShouldFollowNextLinks:YES];
[service setIsServiceRetryEnabled:YES];
5)
//NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:username];
NSURL *url = [[NSURL alloc] initWithString:#”http://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads”];

Attaching a txt-file in mailcomposer ios 7

When use my following script, then the picture and the logfile would be a attached file. Also some other Text (the default signature) from the email would be attached as index.htm to the email when i open it with Outlook.
The Email is sent out from the iPad with iOS 7.0.6
In the Mail-Application on the Mac, the Files are in the middle of the text, before the signature of the mail-application would be written.
When i attach only the image, then all would be fine. When i attache also the logfile.txt, then its like I have descripted and in the Mail-Application of the mac, all special keys (german like ä, ü) are not decoded as utf8.
Where did I make the mistake?
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
currentIOS = [[UIDevice currentDevice] systemVersion];
vNumber = #"V"VersionNumber;
subject = [NSString stringWithFormat:#"%# - Meine aktuelle iPad-Nummer",vNumber];
message = [NSString stringWithFormat:#"<p>Hallo liebes EDV-Team,</p> <p>mein Betriebssystem ist: %#</p><p>Und meine iPad-Nummer lautet: %#</p>", currentIOS, udid];
[controller setToRecipients: [NSArray arrayWithObjects:#"email#webpage.de", nil]];
[controller setSubject:subject];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *txtFilePath = [documentsDirectory stringByAppendingPathComponent:#"logfile.txt"];
NSData *noteData = [NSData dataWithContentsOfFile:txtFilePath];
[controller addAttachmentData:noteData mimeType:#"text/plain" fileName:#"logfile.txt"];
UIImage *roboPic = [UIImage imageNamed:#"world_smilie.png"];
NSData *imageData = UIImagePNGRepresentation(roboPic);
[controller addAttachmentData:imageData mimeType:#"image/png" fileName:#"smile.png"];
[controller setMessageBody:message isHTML:YES];
if ([self respondsToSelector:#selector(presentViewController:animated:completion:)]){
[self presentViewController:controller animated:YES completion:nil];
}
I changed the code for the textfile:
I change the code like elio.d told me:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *txtFilePath = [documentsDirectory stringByAppendingPathComponent:#"logfile.txt"];
NSString *txtFileContent = [NSString stringWithContentsOfFile:txtFilePath encoding:NSUTF8StringEncoding error:nil];
NSData *txtFileData = [txtFileContent dataUsingEncoding:NSUTF8StringEncoding];
[controller addAttachmentData:txtFileData
mimeType:#"text/plain"
fileName:#"logfile.txt"];
The logfile.txt would be attached but the signature from the ipad would be attached to the email in ATT00002.htm and now i got also a empty ATT00001.htm
I have the same problem when i change the type of the email (isHTML:NO)

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!

Resources