Have you been curious about how to open Mail.app from your applications to send contact email? Today, I will be teaching you how to do just that. Â We will even be pre-filling the subject, to line, and body of the email.
This is a great way to to put a contact or bug report button on your app. Â I’m going to start with a simple UI that I created. Â I’m not going to discuss how it was created (I’ll leave that part up to you) as I have gone over Interface Builder quite a few times before. Â
The UI simply consists of 2 UITextFields, a UITextArea, and a UIButton. Â They are all connected to some code inside of the Applications Delegate. Â This is not important, as the focus of this tutorial is to create a reusable function to send mail from your iPhone app. Here is a quick screenshot of the application…
You can download my source code below, or simply start with a basic view-based application and make your own UI. Â So, here is a function that I wrote to send email. Â You can use this function in any application you wish.
Ok, so let me explain what is going on… First, the function takes 3 arguments. Â These are pretty obvious based on their name. Â Next, we are building a string. Â This string will have the format of a URL. Â It’s pretty much the same thing as doing a “mailto” link on a webpage. One thing I want to point out is the fact that I had to use stringByAddingPercentEscapesUsingEncoding . Â Wow, that’s a mouthful. Â You would think Apple could come up with a shorter name. Â Maybe SanitizeURLString or something… Either way, this does all of the special character replacements in the URL. Â So spaces get replaced with %20, etc…
The next thing we do is simply open a URL using the built in openURL method in UIApplication. Â This will cause the iPhone to open up Mail.app and magically, our to, subject, and body are already filled out. Â Here is how I called the function in my app.
I just connected this IBAction to the Mail UIButton in my app. Â So when this method fires, it gets the value of to, subject, and body and passes it to our sendEmailTo method. Â Pretty sweet ehh? Â
That concludes this tutorial. Â If you have any questions or comments feel free to leave them in the comments section or ask me on Twitter. Â You can also download the source here.
Happy iCoding!




Workout of the Day
Pingback: Code for Sending email from your iPhone App | iphonedevelopmentbits
Pingback: iPhone development Tutorials « The Brook Song - à¦à¦°à§à¦£à¦¾à¦° গান
Pingback: 100 Free Courses & Tutorials for Aspiring iPhone App Developers | Best Universities
Pingback: 200ml » 100 Free courses for iPhone Dev
Pingback: 100 реÑурÑов Ð´Ð»Ñ iPhone-разработчиков - Краковецкий ÐлекÑандр: заметки прогÑ
Pingback: Some Great Resources! | My First iPhone Application
Pingback: Online Business Management Software and Services » Blog Archive » The Ultimate Toolbox for iPhone Development
Pingback: The Ultimate Toolbox for iPhone Development - Creative Solutions
Pingback: Enlaces para desarrollar en el iPhone | El mundo de IMD
Pingback: 100 Free Courses & Tutorials for Aspiring iPhone App Developers | c'est la vie
Pingback: 100 Free Courses & Tutorials for Aspiring iPhone App Developers | c'est la vie
Pingback: The Ultimate Toolbox for iPhone Development | c'est la vie
Pingback: The Ultimate Toolbox for iPhone Development | c'est la vie
Pingback: iPhone uygulamaları geliÅŸtirmek isteyenler için ücretsiz 100 kurs ve rehber « Kerem PALABIYIK
Pingback: The Complete iPhone Development Toolbox | iPhoneApp Dev Blog
Pingback: Code for Sending email from your iPhone App | iphone place
Pingback: App development per iOS, i tutorial - TheAppleLounge
Pingback: 100 cursos gratuitos y tutoriales para aspirantes a desarrolladores de App para iphone « Programacion « VENDO MI APPLE