每封邮件发送数据

时间:2012-07-17 07:48:08

标签: xcode email uitextfield iboutlet mail-sender

我正在开发一款应用,但我错过了一小部分内容。我准备了一个View,以便您可以将数据插入UITextField,然后我可以通过电子邮件发送此信息。我尝试了很多方法。

#import <UIKit/UIKit.h>
@interface RMAcpu : UIViewController <UITextFieldDelegate> 
@property  IBOutlet UITextField *prodotto;
@property  IBOutlet UITextField *seriale;
@property  IBOutlet UITextField *cfiva;
@property  IBOutlet UITextField *email;
@property  IBOutlet UITextField *problema;
- (IBAction)inviodati:(id)sender;
@end

关于.m,我试过这个,但不发送信息。你能帮我通过电子邮件发送信息吗?

#import "RMAcpu.h"

@interface RMAcpu ()

@end

@implementation RMAcpu
@synthesize prodotto;
@synthesize seriale;
@synthesize cfiva;
@synthesize email;
@synthesize problema;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}

- (void)viewDidLoad
{
    [super viewDidLoad];


    // Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
    [self setProdotto:nil];
    [self setSeriale:nil];
    [self setCfiva:nil];
    [self setEmail:nil];
    [self setProblema:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)inviodati:(id)sender {
    NSString *stringaMail = [NSString stringWithFormat:@"mailto:cristian@prokoo.com", [[prodotto text] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding], [[seriale text] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding], [[cfiva text]  stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];


    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:stringaMail]];



}
@end

1 个答案:

答案 0 :(得分:1)

除非您实施自己的SMTP客户端,否则无法直接从您的应用发送电子邮件。遵循此方法的当前项目是skpsmtpmessage

如果您不想以这种方式尝试,则需要使用MessageUI框架中的MFMailComposeViewController。这将允许您创建电子邮件模板并预填充收件人,主题和邮件正文等字段,但用户必须手动点击发送按钮。