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!
-
http://www.pierreabiaad.com Pierre
-
Todd
-
http://www.webappgalaxy.com Mark H. Delfs
-
http://iphonedevelopmentbits.com/code-for-sending-email-from-your-iphone-app/ Code for Sending email from your iPhone App | iphonedevelopmentbits
-
http://www.catamount.com Hardy Macia
-
http://girly-photo.blogspot.com/ MyPicture and friend
-
Todd
-
http://fass-software.com Félix Simões
-
RoMa
-
http://brandontreb.com Brandon
-
mahboud
-
Mat
-
http://JoshuaCaputo.com JoshuaCaputo
-
http://JoshuaCaputo.com JoshuaCaputo
-
http://iphone.christosblog.com Christo
-
Stuart
-
http://mossreg.webp.com moss
-
Milan
-
bess
-
http://afruj.wordpress.com/2009/03/24/iphone-tutorials/ iPhone development Tutorials « The Brook Song – à¦à¦°à§à¦£à¦¾à¦° গান
-
Tung Do
-
Tung Do
-
John
-
john
-
http://www.bestuniversities.com/blog/2009/100-free-courses-tutorials-for-aspiring-iphone-app-developers/ 100 Free Courses & Tutorials for Aspiring iPhone App Developers | Best Universities
-
http://cloakedlink.com/wurdokwohh 100% Free Iphone
-
http://cloakedlink.com/wurdokwohh GetAFreeIphone
-
http://howtomakeiphoneapps.com MattjDrake
-
http://www.farfromperfection.com/ Scott
-
Jay
-
Peter
-
http://www.fortuneinfotech.com Rupnarayan
-
http://bricetsjkxgray.blogsome.com Poppy Keant
-
Lakshmikanth
-
http://www.christian-fries.de/iphone/presentationassistant/ Christian Fries
-
http://www.watchyearoneonline.com/ Watch Year One Online Free
-
http://www.ipwngames.com mweeza
-
http://200ml.info/wordpress/?p=12 200ml » 100 Free courses for iPhone Dev
-
http://qwonder.com Rafael
-
http://iphoner.org.ua/blogs/akrakovetsky/archive/2009/07/05/100-iphone.aspx 100 реÑурÑов Ð´Ð»Ñ iPhone-разработчиков – Краковецкий ÐлекÑандр: заметки прогÑ
-
cheebs
-
Sachin
-
jfm
-
Ethan
-
http://www.extenzedeal.com Extenze
-
http://www.yourfreegadget.co.uk Free Gadget
-
http://www.free-mobilephone.co.uk Free Mobile Phone
-
http://www.myfirstiphoneapplication.com/2009/10/some-great-resources/ Some Great Resources! | My First iPhone Application
-
http://www.onlinemagazabayiservisyazilim.com/the-ultimate-toolbox-for-iphone-development.html Online Business Management Software and Services » Blog Archive » The Ultimate Toolbox for iPhone Development
-
http://cs-me.com/2009/11/21/the-ultimate-toolbox-for-iphone-development/ The Ultimate Toolbox for iPhone Development – Creative Solutions
-
http://mundoimd.com/2009/11/30/enlaces-para-desarrollar-en-el-iphone/ Enlaces para desarrollar en el iPhone | El mundo de IMD
-
Nat
-
http://fansibo.com/?p=238 100 Free Courses & Tutorials for Aspiring iPhone App Developers | c'est la vie
-
http://fansibo.com/?p=238 100 Free Courses & Tutorials for Aspiring iPhone App Developers | c'est la vie
-
http://www.chlymidia.org Yasmine Dennis
-
http://fansibo.com/?p=240 The Ultimate Toolbox for iPhone Development | c'est la vie
-
http://fansibo.com/?p=240 The Ultimate Toolbox for iPhone Development | c'est la vie
-
http://kerempalabiyik.com/2010/02/27/iphone-uygulamalari-gelistirmek-isteyenler-icin-ucretsiz-100-kurs-ve-rehber/ iPhone uygulamaları geliÅŸtirmek isteyenler için ücretsiz 100 kurs ve rehber « Kerem PALABIYIK
-
http://iphoneapp.us/the-complete-iphone-development-toolbox/ The Complete iPhone Development Toolbox | iPhoneApp Dev Blog
-
http://iphone.maxi-pulsa.com/?p=327 Code for Sending email from your iPhone App | iphone place
-
http://www.olasz-ales.com alessign
-
http://6050403020.com/ Alfonzo Brancati
-
jeff
-
http://mybirdlists.ginasfamilystore.com gina
-
http://watchmacgruberonlinefree.wetpaint.com Larry Callis
-
http://www.codeobsessed.com Coder
-
http://gadgetax.com Krystina Settlemires
-
http://www.theapplelounge.com/tutorial/app-development-per-ios-i-tutorial/ App development per iOS, i tutorial – TheAppleLounge
-
Carol
-
Carol
-
siva
-
Danielle
-
http://www.uwsp.edu/athletics/mbb/schedule.htm Schedule
-
samar gupta
-
polo
-
http://seo1sem2services3.blogspot.com/ atif yousuf
-
http://www.rapidwriters.net/ Writing Custom Essay
-
http://vendomiapple.com/2011/01/29/100-cursos-gratuitos-y-tutoriales-para-aspirantes-a-desarrolladores-de-app-para-iphone/ 100 cursos gratuitos y tutoriales para aspirantes a desarrolladores de App para iphone « Programacion « VENDO MI APPLE
-
Nehal11
-
Ventura_332
-
Jpatel
-
Minthos
-
Rlsommer
-
Ajith
-
Ajith_ajith3
-
chris
-
chris
-
chris
-
chris
-
Janhavin
-
Ajith-ajith3
-
Ganesh
-
Vaddi Subbu2011
-
http://www.mantrais.com/iphone-application-development.php iPhone App Development



Workout of the Day