ios - How to send an email with SKPSMTPMessage which will parse ok in email clients? -
i've been trying use skpsmtpmessage ios application i'm creating. app send emails right seems there issues regarding email view on clients.
i can see email on gmail example, can't airmail, appears empty email.
looking @ code of email, seems "good" me so, can't know what's going on.
here code sent email.
delivered-to: edited@gmail.com received: 10.194.33.198 smtp id t6csp161338wji; sun, 18 may 2014 01:58:13 -0700 (pdt) x-received: 10.43.138.210 smtp id it18mr25804198icc.23.1400403493134; sun, 18 may 2014 01:58:13 -0700 (pdt) return-path: <bounces+256657-1972-edited=gmail.com@sendgrid.info> received: o1.b99.sendgrid.net (o1.b99.sendgrid.net. [208.115.235.3]) mx.google.com smtp id au7si6505972igc.48.2014.05.18.01.58.12 <edited@gmail.com>; sun, 18 may 2014 01:58:13 -0700 (pdt) received-spf: pass (google.com: domain of bounces+256657-1972-edited=gmail.com@sendgrid.info designates 208.115.235.3 permitted sender) client-ip=208.115.235.3; authentication-results: mx.google.com; spf=pass (google.com: domain of bounces+256657-1972-edited=gmail.com@sendgrid.info designates 208.115.235.3 permitted sender) smtp.mail=bounces+256657-1972-edited=gmail.com@sendgrid.info; dkim=pass header.i=@sendgrid.me dkim-signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:content-type:mime-version:subject:x-feedback-id; s=smtpapi; bh=1gap02jh/1vkt+wxezzuqwstvy0=; b=hfynztr3lneilbouiy slwk1px7lluo/tvq7wdsia1wyv6pbkkx4/jnpxhw3xls4wpgmyrz8xcvbfxxfwix ivxockzjvpg1tnqwzkpry4mw1jfq1ptuv27lduzgankx1lok7ivxuympuk63gogk 0rjcaotalabzwry4qsp8avlfc= received: mf182.sendgrid.net smtp id mf182.18991.537876231 sun, 18 may 2014 08:58:11 +0000 (utc) received: localhost (host-87-242-224-202.ppp.onetel.net.uk [87.242.224.202]) ismtpd-026 (sg) esmtp id 1460e8d79b4.2412.7462b <edited@gmail.com>; sun, 18 may 2014 08:58:11 +0000 (gmt) date: sun, 18 may 2014 09:58:11 +0100 message-id: <1c33afa6a19e4e8f8c9f6e631f64c8c0@smtp.sendgrid.net> from:note@edited.com to:edited@gmail.com content-type: multipart/mixed; boundary="skpsmtpmessage--separator--delimiter" mime-version: 1.0 subject:message me x-sg-eid: bje7cohfb5fdmozj4yleqih38eb2ynrmlxaslfcz07jgi1wxoefgqbqvyj7/w5+f8v5gwapbtnko4vdw1iarlad8chlhkrlegh9r/jepxrz1qcozxpvonevrhnmnnbfhwydd9rn5fzhyfx4lwlmnl28i0b8wm5ogxygrlirhdsw= x-feedback-id: 256657:umrjcmh3m2hiu7p3czoej4qtbrk+kuiuzrdj8e2//mk=:umrjcmh3m2hiu7p3czoej4qtbrk+kuiuzrdj8e2//mk=:sg --skpsmtpmessage--separator--delimiter content-transfer-encoding: 7bit content-type: text/plain; charset=utf-8; format=flowed test --skpsmtpmessage--separator--delimiter --skpsmtpmessage--separator--delimiter--
don't know issue. thing can think of 2 delimiters appended @ end of email can't find either when happening.
this file responsible of sending parts and, attaching separator delimiter.
- (bool)sendparts { nsmutablestring *message = [[nsmutablestring alloc] init]; static nsstring *separatorstring = @"--skpsmtpmessage--separator--delimiter\r\n"; cfuuidref uuidref = cfuuidcreate(kcfallocatordefault); nsstring *uuid = (nsstring *)cfbridgingrelease(cfuuidcreatestring(kcfallocatordefault, uuidref)); cfrelease(uuidref); nsdate *now = [[nsdate alloc] init]; nsdateformatter *dateformatter = [[nsdateformatter alloc] init]; [dateformatter setdateformat:@"eee, dd mmm yyyy hh:mm:ss z"]; [message appendformat:@"date: %@\r\n", [dateformatter stringfromdate:now]]; [message appendformat:@"message-id: <%@@%@>\r\n", [(nsstring *)uuid stringbyreplacingoccurrencesofstring:@"-" withstring:@""], self.relayhost]; [message appendformat:@"from:%@\r\n", fromemail]; if ((self.toemail != nil) && (![self.toemail isequaltostring:@""])) { [message appendformat:@"to:%@\r\n", self.toemail]; } if ((self.ccemail != nil) && (![self.ccemail isequaltostring:@""])) { [message appendformat:@"cc:%@\r\n", self.ccemail]; } [message appendstring:@"content-type: multipart/mixed; boundary=\"skpsmtpmessage--separator--delimiter\"\r\n"]; [message appendstring:@"mime-version: 1.0\r\n"]; [message appendformat:@"subject:%@\r\n\r\n",subject]; [message appendstring:separatorstring]; nsdata *messagedata = [message datausingencoding:nsutf8stringencoding allowlossyconversion:yes]; nslog(@"c: %s", [messagedata bytes]); if (cfwritestreamwritefully((__bridge cfwritestreamref)outputstream, (const uint8_t *)[messagedata bytes], [messagedata length]) < 0) { return no; } message = [[nsmutablestring alloc] init]; (nsdictionary *part in parts) { // checking contains actual part avoid appending separators if ([part objectforkey:kskpsmtppartmessagekey]){ if ([part objectforkey:kskpsmtppartcontentdispositionkey]) { [message appendformat:@"content-disposition: %@\r\n", [part objectforkey:kskpsmtppartcontentdispositionkey]]; } [message appendformat:@"content-transfer-encoding: %@\r\n", [part objectforkey:kskpsmtppartcontenttransferencodingkey]]; [message appendformat:@"content-type: %@\r\n\r\n", [part objectforkey:kskpsmtppartcontenttypekey]]; [message appendstring:[part objectforkey:kskpsmtppartmessagekey]]; [message appendstring:@"\r\n"]; [message appendstring:separatorstring]; } } [message appendstring:@"\r\n.\r\n"]; nslog(@"c: %@", message); if (cfwritestreamwritefully((__bridge cfwritestreamref)outputstream, (const uint8_t *)[message utf8string], [message lengthofbytesusingencoding:nsutf8stringencoding]) < 0) { return no; } [self startlongwatchdog]; return yes; }
when that's logged (at nslog(@"c: %@", message);
), 2 final separators aren't there.
anyone has hint?
as supposed, issue there additional separator wasn't needed @ , hence failure.
so, on sendparts
method, changed this:
[message appendstring:@"content-type: multipart/mixed; boundary=\"skpsmtpmessage--separator--delimiter\"\r\n"]; [message appendstring:@"mime-version: 1.0\r\n"]; [message appendformat:@"subject:%@\r\n\r\n",subject]; [message appendstring:separatorstring];
to this:
[message appendstring:@"content-type: multipart/mixed; boundary=\"skpsmtpmessage--separator--delimiter\"\r\n"]; [message appendstring:@"mime-version: 1.0\r\n"]; [message appendformat:@"subject:%@\r\n\r\n",subject];
basically, removing [message appendstring:separatorstring];
and then, on loop:
for (nsdictionary *part in parts) { // checking contains actual part avoid appending separators if ([part objectforkey:kskpsmtppartmessagekey]){ if ([part objectforkey:kskpsmtppartcontentdispositionkey]) { [message appendformat:@"content-disposition: %@\r\n", [part objectforkey:kskpsmtppartcontentdispositionkey]]; } [message appendformat:@"content-transfer-encoding: %@\r\n", [part objectforkey:kskpsmtppartcontenttransferencodingkey]]; [message appendformat:@"content-type: %@\r\n\r\n", [part objectforkey:kskpsmtppartcontenttypekey]]; [message appendstring:[part objectforkey:kskpsmtppartmessagekey]]; [message appendstring:@"\r\n"]; [message appendstring:separatorstring]; } }
i moved separatorstring
top of appending operation:
for (nsdictionary *part in parts) { // checking contains actual part avoid appending separators if ([part objectforkey:kskpsmtppartmessagekey]){ [message appendstring:separatorstring]; if ([part objectforkey:kskpsmtppartcontentdispositionkey]) { [message appendformat:@"content-disposition: %@\r\n", [part objectforkey:kskpsmtppartcontentdispositionkey]]; } [message appendformat:@"content-transfer-encoding: %@\r\n", [part objectforkey:kskpsmtppartcontenttransferencodingkey]]; [message appendformat:@"content-type: %@\r\n\r\n", [part objectforkey:kskpsmtppartcontenttypekey]]; [message appendstring:[part objectforkey:kskpsmtppartmessagekey]]; [message appendstring:@"\r\n"]; } }
this solve issue!
Comments
Post a Comment