Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用SKPSMTPMessage发送电子邮件,它将在电子邮件客户端中解析ok?_Ios_Objective C_Email_Ios7_Smtp - Fatal编程技术网

Ios 如何使用SKPSMTPMessage发送电子邮件,它将在电子邮件客户端中解析ok?

Ios 如何使用SKPSMTPMessage发送电子邮件,它将在电子邮件客户端中解析ok?,ios,objective-c,email,ios7,smtp,Ios,Objective C,Email,Ios7,Smtp,我一直在尝试使用我正在创建的iOS应用程序。该应用程序现在确实发送电子邮件,但似乎在某些客户端的电子邮件查看方面存在一些问题 例如,我可以在Gmail上正确地看到电子邮件,但我不能正确地看到航空邮件,它看起来是一封空电子邮件 看这封邮件的代码,对我来说似乎“很好”,所以我不知道发生了什么 这是作为电子邮件发送的代码 Delivered-To: edited@gmail.com Received: by 10.194.33.198 with SMTP id t6csp161338wji;

我一直在尝试使用我正在创建的iOS应用程序。该应用程序现在确实发送电子邮件,但似乎在某些客户端的电子邮件查看方面存在一些问题

例如,我可以在Gmail上正确地看到电子邮件,但我不能正确地看到航空邮件,它看起来是一封空电子邮件

看这封邮件的代码,对我来说似乎“很好”,所以我不知道发生了什么

这是作为电子邮件发送的代码

Delivered-To: edited@gmail.com
Received: by 10.194.33.198 with SMTP id t6csp161338wji;
        Sun, 18 May 2014 01:58:13 -0700 (PDT)
X-Received: by 10.43.138.210 with 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: from o1.b99.sendgrid.net (o1.b99.sendgrid.net. [208.115.235.3])
        by mx.google.com with SMTP id au7si6505972igc.48.2014.05.18.01.58.12
        for <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 as 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 as 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: by mf182.sendgrid.net with SMTP id mf182.18991.537876231
        Sun, 18 May 2014 08:58:11 +0000 (UTC)
Received: from localhost (host-87-242-224-202.ppp.onetel.net.uk [87.242.224.202])
  by ismtpd-026 (SG) with ESMTP id 1460e8d79b4.2412.7462b
  for <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 from 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

This is a test
--SKPSMTPMessage--Separator--Delimiter


--SKPSMTPMessage--Separator--Delimiter--
交付给:edited@gmail.com
收到日期:198年10月194日前,SMTP id为t6csp161338wji;
2014年5月18日星期日01:58:13-0700(PDT)
X-Received:10.43.138.210,SMTP id为it18mr25804198icc.23.1400403493134;
2014年5月18日星期日01:58:13-0700(PDT)
返回路径:
接收:来自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
对于
2014年5月18日星期日01:58:13-0700(PDT)
收到SPF:pass(google.com:domain of bounces+256657-1972-edited=gmail)。com@sendgrid.info指定208.115.235.3为允许的发送方)客户端ip=208.115.235.3;
认证结果:mx.google.com;
spf=pass(google.com:domain of bounces+256657-1972-edited=gmail)。com@sendgrid.info指定208.115.235.3为允许的发件人)smtp.mail=bounces+256657-1972-edited=gmail。com@sendgrid.info;
dkim=passheader.i=@sendgrid.me
DKIM签名:v=1;a=rsa-sha1;c=放松;d=sendgrid.me;
h=从:到:内容类型:mime版本:主题:x-feedback-id;
s=smtpapi;bh=1gap02jh/1VKT+wxEZZuQWStvy0=;b=HFYnzTR3lNEIlBOuiy
SLwK1Px7Lluo/tVq7wdsIa1Wyv6pbkKx4/JnPxhw3xls4WPgmyrZ8xCvbFXXFWIx
IvXoCkZJvpg1TNqwZkpry4mW1JfQ1PTUv27lDUZGANkX1Lok7IVxUyMPuK63gOgK
0rjCAoTALabZWrY4qSP8aVlfc=
接收:由mf182.sendgrid.net发送,SMTP id为mf182.18991.537876231
2014年5月18日星期日08:58:11+0000(UTC)
收到:来自本地主机(主机-87-242-224-202.ppp.onetel.net.uk[87.242.224.202])
通过带ESMTP id 1460e8d79b4.2412.7462b的ismtpd-026(SG)
对于2014年5月18日星期日08:58:11+0000(格林尼治标准时间)
日期:2014年5月18日星期日09:58:11+0100
消息id:
发件人:note@edited.com
致:edited@gmail.com
内容类型:多部分/混合;boundary=“SKPSMTPMessage--分隔符--分隔符”
Mime版本:1.0
主题:我的留言
X-SG-EID:BJE7COHFB5FDMOZJ4YLEQIH38EB2YNRMLXSLFCZ07JGI1WXOEFGQBQVYJ7/w5+F8V5GwWPTNKO4VDW1iarLad8ChlHKRLEGH9R/JEPXRZ1QCOzPxPvonnHwyd9Rn5FzHyFX4LWLM28I0B8Wm5OgxygrlRhDSW=
X-Feedback-ID:256657:UMRJCM3M2HIU7P3CZOEJ4QTBRK+KuIuZrDj8e2//Mk=:UMRJCM3M2HIU7P3CZOEJ4QTBRK+KuIuZrDj8e2//Mk=:SG
--SKPSMTPMessage--分隔符--分隔符
内容传输编码:7bit
内容类型:文本/纯文本;字符集=UTF-8;
格式=流动
这是一个测试
--SKPSMTPMessage--分隔符--分隔符
--SKPSMTPMessage--分隔符--分隔符--
我真的不知道这个问题。我能想到的唯一一件事是,在电子邮件的末尾附加了两个分隔符,但我找不到这是什么时候发生的

负责发送零件并附上分隔符

- (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];

    for (NSDictionary *part in parts)
    {
        // Checking it contains the actual part to 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;
}
-(BOOL)sendParts
{
NSMutableString*消息=[[NSMutableString alloc]init];
静态NSString*separatorString=@--SKPSMTPMessage--Separator--Delimiter\r\n”;
CFUUIDRef uuidRef=cfuuiddcreate(kcfolocatordefault);
NSString*uuid=(NSString*)CfBrigingRelease(CFUUIDCreateString(kCFAllocatorDefault,uuidRef));
CFRelease(uuidRef);
NSDate*now=[[NSDate alloc]init];
NSDateFormatter*dateFormatter=[[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@“EEE,dd-MMM-yyy-HH:mm:ss-Z”];
[邮件附件格式:@“日期:%@\r\n”,[dateFormatter stringFromDate:now];
[message appendFormat:@“message id:\r\n”,[(NSString*)uuid stringByReplacingOccurrencesOfString:@“-”with string:@“],self.relayHost];
[邮件格式:@“发件人:%@\r\n”,发件人电子邮件];
if((self.toEmail!=nil)&&(![self.toEmail IsequalString:@”“]))
{
[邮件格式:@“收件人:%@\r\n”,self.toEmail];
}
if((self.ccEmail!=nil)&&(![self.ccEmail IsequalString:@”“]))
{
[邮件格式:@“Cc:%@\r\n”,self.ccEmail];
}
[消息附件字符串:@“内容类型:多部分/混合;边界=\”SKPSMTPMessage--分隔符--分隔符\“\r\n”];
[消息附录字符串:@“Mime版本:1.0\r\n”];
[邮件格式:@“主题:%@\r\n\r\n”,主题];
[消息附件字符串:分隔符字符串];
NSData*messageData=[消息数据使用编码:NSUTF8StringEncoding allowLossyConversion:是];
NSLog(@“C:%s”,[messageData字节]);
if(cfWriteStreamWritely((uu桥CFWriteStreamRef)输出流,(const uint8_t*)[messageData字节],[messageData长度])小于0
{
返回否;
}
message=[[NSMutableString alloc]init];
用于(NSDictionary*零件中的零件)
{
//检查它是否包含实际零件,以避免附加分隔符
if([part objectForKey:kSKPSMTPPartMessageKey]){
if([part objectForKey:kSKPSMTPPartContentDispositionKey])
{
[消息附件格式:@“内容处置:%@\r\n”,[part objectForKey:kSKPSMTPPartContentDispositionKey]];
}
[消息附件格式:@“内容传输编码:%@\r\n”,[part objectForKey:KSKPSMTPPartContentTransfernCodingKey];
[message appendFormat:@“内容类型:%@\r\n\r\n”,[part objectForKey:kSKPSMTPPartContentTypeKey];
[message appendString:[part objectForKey:kSKPSMTPPartMessageKey]];
[消息附件字符串:@“\r\n”];
[消息附件字符串:分隔符字符串];
}
}
[消息附件字符串:@“\r\n.\r\n”];
NSLog(@“C:%@”,消息);
如果(CFWriteStreamWritely((uu桥CFWriteStreamRef)输出流,(const uint8_t*)[message UTF8String],[message LengthofBytes SusingCodeding:NSUTF8StringEncoding])<0)
{
返回否;
}
[自我监督];
ret
[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];
[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];
for (NSDictionary *part in parts)
{
    // Checking it contains the actual part to 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];
    }
}
for (NSDictionary *part in parts)
{
    // Checking it contains the actual part to 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"];
    }
}
Content-Type: multipart/mixed; boundary=SKPSMTPMessage--Separator--Delimiter
let fileMessagePart1 :[String : String] = [
    kSKPSMTPPartContentTypeKey: "image/jpg;\r\n\tname=\"\(fileName)\"",
    kSKPSMTPPartContentDispositionKey: "attachment;\r\n\tfilename=\"\(fileName)\"",
    kSKPSMTPPartMessageKey: fileData.encodeBase64ForData(),
    kSKPSMTPPartContentTransferEncodingKey: "base64",
]
let emailMessage = SKPSMTPMessage()
// ...
emailMessage.parts = [fileMessagePart1, fileMessagePart2, fileMessagePart3]