3

我正在使用 SKPSMTPMessage 从我们的应用程序发送电子邮件。这使我们可以在电子邮件中附加图片并自动发送该图片,而无需用户点击发送按钮。这非常适合将图像发送到电子邮件帐户。但是,我刚刚尝试通过 Verizon 将图像发送到我的手机,并通过 ATT 将图像发送到我的同事手机,两者都作为 MMS 消息使用这些格式 123456789@vzwpix.com 和 1234567890@mms.att.com。疯狂的是,这些消息显示在我的 gmail 发送项目中,但从未作为彩信发送到手机。但是,如果我登录到 gmail 并将完全相同的消息转发到 123456789@vzwpix.com,则消息会顺利传递。图像大小也只有 42KB 左右。

我对此感到非常困惑,我想知道我是否没有以 gmail 可以理解的方式格式化消息,因此 gmail 无法正确地将消息传递到电话。这是我用来撰写电子邮件的代码

     SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];
    testMsg.fromEmail = [[NSUserDefaults standardUserDefaults] stringForKey:[NSString stringWithFormat:@"%@emUsername_key", preset]];
    testMsg.toEmail = [[NSUserDefaults standardUserDefaults] stringForKey:[NSString stringWithFormat:@"%@toEmail_key", preset]];
    testMsg.relayHost = [[NSUserDefaults standardUserDefaults] stringForKey:[NSString stringWithFormat:@"%@emailServer_key", preset]];
    testMsg.port = [[NSUserDefaults standardUserDefaults] stringForKey:[NSString stringWithFormat:@"%@emailPort_key", preset]];
    testMsg.requiresAuth = [[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithFormat:@"%@requiresAuth_key", preset]];
    testMsg.login = [[NSUserDefaults standardUserDefaults] stringForKey:[NSString stringWithFormat:@"%@emUsername_key", preset]];
    testMsg.pass = [[NSUserDefaults standardUserDefaults] stringForKey:[NSString stringWithFormat:@"%@emPassword_key", preset]];
    testMsg.subject = [[NSUserDefaults standardUserDefaults] stringForKey:[NSString stringWithFormat:@"%@emailSubject_key", preset]];
    testMsg.wantsSecure = [[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithFormat:@"%@secureEmail_key", preset]];

    NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
    [f setNumberStyle:NSNumberFormatterDecimalStyle];
    NSNumber * customPort = [f numberFromString:testMsg.port];
    defaultPorts = [[NSArray alloc] initWithObjects:customPort, [NSNumber numberWithShort:587], [NSNumber numberWithShort:25], [NSNumber numberWithShort:465], nil];
    [f release];
    testMsg.relayPorts = defaultPorts;
    testMsg.delegate = self;
    NSString *image_path = [NSString stringWithFormat:@"%@/%@", dir, file];
    NSData *imageData1 = [NSData dataWithContentsOfFile:image_path];// sendImage is a UIImage *sendImage which contains original image and I defined it in Global.h
    NSString* theFileExt = [[file lastPathComponent] pathExtension];
    NSString *fileTitle1;
    NSString *fileTitle2 = [NSString stringWithFormat:@"attachment;\r\n\tfilename=\"%@\"", title];
    NSDictionary *vcfPart;

    if([theFileExt compare:@"png"] == NSOrderedSame){
        fileTitle1 = [NSString stringWithFormat:@"image/png;\r\n\tx-unix-mode=0644;\r\n\tname=\"%@\"", title];
    }else if([theFileExt compare:@"jpg"] == NSOrderedSame){
        fileTitle1 = [NSString stringWithFormat:@"image/jpg;\r\n\tx-unix-mode=0644;\r\n\tname=\"%@\"", title];
    }

    encodedString = nil;

    size_t outBufferEstLength = EstimateBas64EncodedDataSize([imageData1 length]) + 1;
    char *outBuffer = calloc(outBufferEstLength, sizeof(char));

    size_t outBufferLength = outBufferEstLength;
    if (Base64EncodeData([imageData1 bytes], [imageData1 length], outBuffer, &outBufferLength))
    {
        encodedString = [NSString stringWithCString:outBuffer encoding:NSASCIIStringEncoding];
    }
    else
    {
        [NSException raise:@"NSData+Base64AdditionsException" format:@"Unable to encode data!"];
    }

    free(outBuffer);

    vcfPart = [NSDictionary dictionaryWithObjectsAndKeys:fileTitle1,kSKPSMTPPartContentTypeKey,
               fileTitle2,kSKPSMTPPartContentDispositionKey,encodedString,kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil];
    NSString * bodyMessage = [[NSUserDefaults standardUserDefaults] stringForKey:[NSString stringWithFormat:@"%@emailSignature_key", preset]];
    NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey,
                               bodyMessage ,kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];
    testMsg.parts = [NSArray arrayWithObjects:plainPart,vcfPart,nil];
    [testMsg send];
    [encodedString release];

这是在 gmail 上检查邮件内容时生成并显示的标题

Return-Path: <myACCT@gmail.com>
Received: from localhost (000.sub-000-000-000.myvzw.com. [000.000.000.000])
    by mx.google.com with ESMTPS id lotsOfStoof.0.2013.01.06.15.22.03
    (version=TLSv1/SSLv3 cipher=OTHER);
    Sun, 06 Jan 2013 15:22:05 -0800 (PST)
Message-ID: <some.stuff.here.kids@mx.google.com>
Date: Sun, 06 Jan 2013 15:22:05 -0800 (PST)
From: myACCT@gmail.com
To: 123456789@vzwpix.com
Content-Type: multipart/mixed; boundary=SKPSMTPMessage--Separator--Delimiter
Mime-Version: 1.0 (SKPSMTPMessage 1.0)
Subject: MYAPP!

--SKPSMTPMessage--Separator--Delimiter
Content-Type: text/plain
Content-Transfer-Encoding: 8bit

Sent from MYAPP. Get it on iTunes!
--SKPSMTPMessage--Separator--Delimiter
Content-Disposition: attachment;
filename="MYAPPIMAGENAME"
Content-Type: image/jpg;
x-unix-mode=0644;
name="MYAPPIMAGENAME"
Content-Transfer-Encoding: base64

任何指导都会很棒。提前致谢!

编辑:我一直在搞砸这个问题,但仍然无法弄清楚是什么原因造成的。我知道gmail可以中继消息。我错过了什么?

谢谢

4

0 回答 0