我有一個由文本字段(5個字段)組成的聯繫表單,我希望通過電子郵件發送到一個電子郵件地址。我如何在xCode中執行此操作?發送電子郵件中的聯繫人表單字段
0
A
回答
0
鏈接的帖子有類似的答案,但我添加了我的代碼,因爲它已經檢查了canSendMail。我還留下了一堆評論代碼,可以很容易地在電子郵件中添加其他內容。
注意,這基本上是比較容易,如果你只指定的iOS 5
我有一個免費的應用程序,QCount,使用此代碼。事實上,我希望我的一切剝離定製從我的複製和粘貼:-) http://itunes.apple.com/ng/app/qcount/id480084223?mt=8
享受,
達明
在你的.h:
#import <MessageUI/MessageUI.h>
方法在你的。米:
- (void)emailLabelPressed { // or whatever invokes your email
// Create a mail message in the user's preferred mail client
// by opening a mailto URL. The extended mailto URL format
// is documented by RFC 2368 and is supported by Mail.app
// and other modern mail clients.
//
// This routine's prototype makes it easy to connect it as
// the action of a user interface object in Interface Builder.
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil)
{
// We must always check whether the current device is configured for sending emails
if ([mailClass canSendMail])
{
[self displayComposerSheet];
}
else
{
[self launchMailAppOnDevice];
}
}
else
{
[self launchMailAppOnDevice];
}
}
-(void)displayComposerSheet {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Your Form Subject"];
// Take screenshot and attach (optional, obv.)
UIImage *aScreenshot = [self screenshot];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(aScreenshot)];
[picker addAttachmentData:imageData mimeType:@"image/png" fileName:@"screenshot"];
// Set up the recipients.
NSArray *toRecipients = [NSArray arrayWithObjects:@"[email protected]", nil];
// NSArray *ccRecipients = [[NSArray alloc] init];
// NSArray *bccRecipients = [[NSArray alloc] init];
// NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil];
// NSArray *bccRecipients = [NSArray arrayWithObjects:@"[email protected]", nil];
[picker setToRecipients:toRecipients];
// [picker setCcRecipients:ccRecipients];
// [picker setBccRecipients:bccRecipients];
// Attach an image to the email.
/* NSString *path = [[NSBundle mainBundle] pathForResource:@"ipodnano"
ofType:@"png"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"image/png"
fileName:@"ipodnano"];
*/
// Fill out the email body text.
// NSString *emailBody = @"Use this for fixed content.";
NSMutableString *emailBody = [[NSMutableString alloc] init];
[emailBody setString: @"Feedback"];
// programmatically add your 5 fields of content here.
[picker setMessageBody:emailBody isHTML:NO];
// Present the mail composition interface.
if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]) {
[self presentViewController:picker animated:YES completion:nil];
} else {
[self presentModalViewController:picker animated:YES];
}
}
- (void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError *)error {
if ([self respondsToSelector:@selector(dismissViewControllerAnimated:completion:)]) {
[self dismissViewControllerAnimated:YES completion:nil];
} else {
[self dismissModalViewControllerAnimated:YES];
}
}
-(void)launchMailAppOnDevice {
NSString *recipients = @"mailto:[email protected][email protected],[email protected]&subject=Hello from California!";
NSString *body = @"&body=Feedback";
NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}
1
對於任何人在這個問題上磕磕絆絆,你可以使用thi的iOS聯繫表格。
這適合我的需求,它使用PHP組件來實際發送電子郵件。 (包含在示例項目的示例腳本
我把它貼到這裏Github上:
+0
非常感謝你分享這個,很棒!:-) – kernix 2012-11-24 21:01:39
相關問題
- 1. 聯繫表格不發送發件人電子郵件
- 2. 的Joomla單聯繫表單組件不發送電子郵件
- 3. CRM - 發送電子郵件給子網格中的聯繫人
- 4. Ajax聯繫表格未在電子郵件中發送「郵件」字段
- 5. 將css樣式集成到我的電子郵件中發送給聯繫人表單電子郵件
- 6. 在PHP中創建聯繫人表單併發送電子郵件
- 7. 將magento聯繫表格電子郵件的「From」字段更改爲發件人
- 8. 聯繫表單工作,發送電子郵件,信息丟失
- 9. 通過聯繫表格發送郵件到電子郵件ID
- 10. 聯繫表格電子郵件發送,但郵件在主題
- 11. 如何以電子郵件的方式向電子郵件聯繫人發送電子郵件?
- 12. 如何使用javascript將表單聯繫人發送到電子郵件?
- 13. 簡單的電子郵件聯繫表
- 14. 發送電子郵件給多個聯繫人
- 15. 從表單發送的電子郵件未送達收件人
- 16. 在html電子郵件中發送表單字段
- 17. 發送電子郵件:更改「發件人」字段不好?
- 18. MVC3聯繫表格郵寄後不發送電子郵件
- 19. PHP聯繫表格發送電子郵件中沒有內容
- 20. 把帳戶的聯繫人列表放在電子郵件的cc字段中
- 21. django發送聯繫表格到電子郵件引發錯誤
- 22. 的Joomla 2.5,電子郵件聯繫人
- 23. 修改聯繫人表單腳本以插入發件人電子郵件回覆字段
- 24. PHP電子郵件結合字段發送電子郵件
- 25. 確定電子郵件發件人併發送電子郵件
- 26. 聯繫表格不發送電子郵件到我的地址
- 27. 通過電子郵件發送問題的Azure PHP聯繫表
- 28. 發送聯繫表格後的奇怪電子郵件
- 29. php聯繫表格發送沒有信息的電子郵件
- 30. 聯繫表格發送沒有數據的電子郵件
前[SO](http://stackoverflow.com/questions/7087199/xcode已回答-4-ios-send-an-email-using-smtp-from-inside-my-app) – 2012-02-11 00:33:45