2

I am trying to send an HTML email from my SKPSMTP code in iOS. Right now, I'm just sending plain text, but I'm trying to upgrade that a little. I've included that code below.

I can't find any documentation. How can I upload an HTML file and include that as it's body. Also, there's an image that's being loaded from the same directory as the HTML file, if that makes a difference in the answer. Thanks.

 NSMutableString *emailBody = [NSMutableString stringWithFormat:@"Here's your code again, "];
                [emailBody appendString:userCode];
                SKPSMTPMessage *email = [[SKPSMTPMessage alloc] init];
                email.fromEmail = @"me@gmail.com";
                NSString *toEmail = [NSString stringWithFormat:@"%@", self.loginInput.text];
                email.toEmail = toEmail;
                email.relayHost = @"smtp.gmail.com";
                email.requiresAuth = YES;
                email.login = @"me@gmail.com";
                email.pass = @"myPass";
                email.subject = @"Your Validation Code";
                email.wantsSecure = YES;
                email.delegate = self;
                NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey,
                                           emailBody,kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey, nil];
                email.parts = [NSArray arrayWithObjects:plainPart, nil];
                // Send it!
                [email send];
4

1 に答える 1

3

だから、ここに私が見つけた答えがあります.

 //Send them an e-mail
NSError* error = nil;
NSString *path = [[NSBundle mainBundle] pathForResource: @"loginEmail" ofType: @"html"];
NSString *result = [NSString stringWithContentsOfFile: path encoding:
                    NSUTF8StringEncoding error: &error];
NSRegularExpression *regex = [NSRegularExpression
                              regularExpressionWithPattern:@"<!--INJECT CODE HERE -->"
                              options:0
                              error:&error];
NSString *emailBody = [regex stringByReplacingMatchesInString:result options:0 range:NSMakeRange(0, [result length]) withTemplate:code];
NSLog(@"%@", [emailBody class]);
SKPSMTPMessage *email = [[SKPSMTPMessage alloc] init];
email.fromEmail = @"myemail@gmail.com";
NSString *toEmail = [NSString stringWithFormat:@"%@", self.loginInput.text];
email.toEmail = toEmail;
email.relayHost = @"smtp.gmail.com";
email.requiresAuth = YES;
email.login = @"myemail@gmail.com";
email.pass = @"myPass"
email.subject = @"Your Validation Code";
email.wantsSecure = YES;
email.delegate = self;
NSDictionary *htmlPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/html",kSKPSMTPPartContentTypeKey,                    emailBody,kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey, nil];
email.parts = [NSArray arrayWithObjects:htmlPart,  nil];
// Send it!
NSLog(@"ABOUT TO SEND");
[email send];

そのため、HTML ファイルを作成し、すべての画像を tinypic でホストして HTML に含める必要があり、正規表現にテキストを書き込んでコード変数を切り替え、ここにロードして、キーを使用してメールの一部として添付する必要がありました」テキスト/html". このコードは機能しますが、他に役立つ提案があれば、正解としてマークします!

于 2013-08-06T19:45:19.377 に答える