email in iOS

I’m glad you figured it out.

I have made a download of the example project. When I try to compile it, I got this error message:

ld: framework not found framework

there’s probably a declare into a library named “framework” somewhere

try searching for lib "framework"

Please download the entire iOSKit from github:
https://github.com/kingj5/iOSKit

The old projects posted on various threads are no longer guaranteed to work.

Opening up this old thread again, I was wondering if anyone knows how to use Jason’s iOSKit for sending attachments to the email in iOS?

In Jason’s code below you can send an email message, but I don’t see anything in the example to add an attachment.

[code]mailComposeView = new Extensions.MFMailComposeViewController
mailComposeView.setToRecipients Array(“email@example.com”)
mailComposeView.setCcRecipients Array(“email@example.com”)
mailComposeView.setBccRecipients Array(“email@example.com”)
mailComposeView.setSubject “This is a sample email”

if Extensions.MFMailComposeViewController.canSendMail then
mailComposeView.PresentInView(self)
end if[/code]

I see the method addAttachment, but I don’t know how to implement it.

declare sub addAttachment_ lib MessageUIKitLib selector "addAttachmentData:mimeType:fileName:" _ (obj_id as ptr, data as ptr, MIMEType as CFStringRef, fileName as CFStringRef) addAttachment_(self,NSDataFromFolderitem(attachment), MIMEType, fileName)

The name of my file is Roster.sqlite. I was wondering if anyone knows how I can add the functionality to be able to send the database file with Jason’s mailComposeView code above.

I have never tried to use these functions as I use my own transactional email system in iOS.

But I believe you need to pass a xojo.io.folderitem to NSDataFromFolderItem function and you could use application/x-sqlite3 as MIMEType

Hi Jeremie,

Thank you for your message. That link that posted is not working. Can you try it again?

Thanks!

You should be able to call the addAttachment function with the parameters Jeremie specified.

Hi Jason and Jeremie. I just don’t know how to do that. How do your write it and add it to the above code?

I think the forum created the link automatically when Jrmie wrote xojo. io. folderitem

Exactly, just modified my post to remove the link.

I have this line:

Dim f As xojo.io.folderitem = Mailcomposeview.addAttachment(f,”application/x-sqlite3”, “roster.sqlite”)

I made f a xojo.io.folderitem property in the view. When I run this I get that application does not exist.

James I think your code looks fine as I use something very similar (see below) to send a log file via email using Jason’s class:

//Attach log
If logFile <> Nil And logFile.exists Then
    Email.AddAttachment(logFile, "text/xml charset=utf-8", logFile.Name)
End If

I think the problem you have might be to do with the mime type that you’re using. Could it be that you need something other than “application/x-sqlite3” ?

Jason, I don’t know what that would be. I’m using Jason King’s iOSKit and I don’t know what the proper line of code it would be. It’s an SQLite database file I want to send.

Try “application/octet-stream”, which is a generic MIME Type that indicates raw binary content, so the receiving application doesn’t try to find a preview plugin or application to automatically open the content in.

It could be your Email class is err’ing on the “x-sqlite3” type because Email clients wouldn’t typically have a previewer or plugin to automatically handle interaction with a SQLite db.

Jason Tait’s example probably works fine because an XML file is just text after all, and most email clients would be able to handle that.

I hope that helps.

James I don’t think there’s anything wrong with your code and I use the same iOSKit class that you do without problem. It looks to me that it might be the mime type for “application/x-sqlite3”.

Dim f As xojo.io.folderitem = Mailcomposeview.addAttachment(f,”application/octet-stream”, “roster.sqlite”)

Scott that throws the same error when building. It highlights application and reports, "This item does not exist.

Jason, I just added this code to Jason King’s example. I’m using his example, not my project:

[code]mailComposeView = new Extensions.MFMailComposeViewController
mailComposeView.setToRecipients Array(“email@example.com”)
mailComposeView.setCcRecipients Array(“email@example.com”)
mailComposeView.setBccRecipients Array(“email@example.com”)
mailComposeView.setSubject “This is a sample email”

Dim f As xojo.io.folderitem = Mailcomposeview.addAttachment(f,”application/x-sqlite3”, “roster.sqlite”)

if Extensions.MFMailComposeViewController.canSendMail then
mailComposeView.PresentInView(self)
end if[/code]

It first throws an error that f does not exist. So I created a property f as xojo.io.folderitem

I then get the error.
It highlights application and reports, "This item does not exist.

Where is application suppose to be defined? Its doesn’t look like Jason defined it anywhere. If I take out the attachment line, it will send an email just fine, so I’m doing something wrong here somewhere. I just don’t know what it is. Sorry, I’m just really confused.

The problem in the code you’ve posted above is that you need to pass a FolderItem to the AddAttachment method. It doesn’t return a FolderItem.

So you want to create your folder item, eg here’s a bit of what I do:

Dim logFile As FolderItem = SpecialFolder.Temporary.Child(logFilename)

Then you want to pass that folder item to AddAttachment along with the mine type and filename:

Mailcomposeview.AddAttachment(logFile, "text/xml charset=utf-8", logFile.Name)

You don’t need to make f (or logFile in my example) a property of the view. However you do need to make your Mailcomposeview (a Extensions.MFMailComposeViewController class) a property of the view as you need it to hang around.

[quote=368333:@James Redway]I have this line:

Dim f As xojo.io.folderitem = Mailcomposeview.addAttachment(f,”application/x-sqlite3”, “roster.sqlite”)

I made f a xojo.io.folderitem property in the view. When I run this I get that application does not exist.[/quote]

Maybe it should be:

Dim f As Xojo.io.folderitem = SpecialFolder.Documents("roster.sqlite") Mailcomposeview.addAttachment(f, "application/x-sqlite3", f.name)

Yes that’s it.