我正在使用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可以传递消息。我错过了什么?由于