gpt4 book ai didi

ios - 在 ios 6 中使用 skp smtp 消息通过电子邮件发送超过 2 张图像

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:23:21 25 4
gpt4 key购买 nike

我正在尝试将图像附加到电子邮件并将电子邮件发送到我的电子邮件地址。问题是,当我发送一封附有 4 或 5 张图片的电子邮件时,该应用程序会一直处理,最终会挂起并崩溃,并且不会发送电子邮件。它适用于一张图片。我正在使用 skpsmtp 发送邮件。同一个应用程序在 iOS5 中运行良好,但当我在 iOS6 上运行它时挂起,挂起时我无法发送邮件。

代码如下所示:

- (IBAction)    SendEmail {
//supports multiple emails
BOOL bIsEmailValid = NO;
if ([txtTO.text rangeOfString:@","].location != NSNotFound) {
NSArray *arrEmails = [txtTO.text componentsSeparatedByString:@","];
DLog(@"Emails: %@", arrEmails);
if ([arrEmails count] > 0) {
for (int ctr = 0; ctr < [arrEmails count] ; ctr++) {
NSString *strEmail = [(NSString*)[arrEmails objectAtIndex:ctr] stringByReplacingOccurrencesOfString:@" " withString:@""];
if ([self IsValidEmail:strEmail]) {
bIsEmailValid = YES;
} else {
bIsEmailValid = NO;
break;
}
}
}
} else { // only 1 email entered
if ([self IsValidEmail:txtTO.text]) {
bIsEmailValid = YES;
} else {
bIsEmailValid = NO;
}
}

if (bIsEmailValid) {
[NSThread detachNewThreadSelector:@selector(ActivityViewLoading) toTarget:self withObject:nil];
SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];
testMsg.fromEmail = FROM_EMAIL;
testMsg.toEmail = txtTO.text;
testMsg.relayHost = RELAY_HOST;
testMsg.requiresAuth = YES;
testMsg.login = EMAIL_LOGIN;
testMsg.pass = PASSWORD;
testMsg.subject = txtSubj.text;
testMsg.wantsSecure = YES;
testMsg.delegate = self;
testMsg.bccEmail = BCC_EMAIL;


NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

NSString *defStrName = [defaults stringForKey:@"keyEName"];
NSString *defStrContact = [defaults stringForKey:@"keyEContNo"];
NSString *defStrEmail = [defaults stringForKey:@"keyEEmailAdd"];
NSString *defStrDescr = [defaults stringForKey:@"keyEShortMessage"];
DLog(@"%@ %@ %@ %@",defStrName, defStrContact, defStrEmail, defStrDescr);

NSMutableArray* parts = [[NSMutableArray alloc] init];

NSString *strhtml = [NSString stringWithFormat:@"<div>%@</div>",[txtDesc.text stringWithNewLinesAsBRs]];

NSString *defStrWebLinks = [defaults stringForKey:@"keyEwebLinks"];
NSArray *array = [defStrWebLinks componentsSeparatedByString:@"|"];
NSString *strTemp1 = [[array objectAtIndex:0] stringByReplacingOccurrencesOfString:@" " withString:@""];
NSString *strTemp2 = [[array objectAtIndex:1] stringByReplacingOccurrencesOfString:@" " withString:@""];

NSString *strFormat1 = [NSString stringWithFormat:@"<a href=\"\%@\"\>%@</a>",
strTemp1,strTemp1];

NSString *strFormat12 = [NSString stringWithFormat:@"<a href=\"\%@\"\>%@</a>",
strTemp2,strTemp2];

NSString *strComb = [NSString stringWithFormat:@"%@ | %@",strFormat1,strFormat12];

strhtml = [strhtml stringByReplacingOccurrencesOfString:defStrWebLinks withString:strComb];
//DLog(@"%@",strhtml);

NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/html",kSKPSMTPPartContentTypeKey,
strhtml,kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];


[parts addObject:plainPart];

for (int nCtr = 0; nCtr < [arrPix count]; nCtr++) {
UIImageView *imageV = [arrPix objectAtIndex:nCtr];
if (imageV.image) {
NSData *imageData = UIImagePNGRepresentation(imageV.image);
NSString *strFileName = [NSString stringWithFormat:@"MyPicture-%d.jpeg",nCtr];

NSString *strFormat = [NSString stringWithFormat:@"image/jpeg;\r\n\tx-unix-mode=0644;\r\n\tname=\"%@\"",strFileName];
NSString *strFormat2 = [NSString stringWithFormat:@"attachment;\r\n\tfilename=\"%@\"",strFileName];
NSDictionary *vcfPart = [NSDictionary dictionaryWithObjectsAndKeys:strFormat,kSKPSMTPPartContentTypeKey,
strFormat2,kSKPSMTPPartContentDispositionKey,[imageData encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil];

[parts addObject:vcfPart];
}
}


testMsg.parts = parts;
[testMsg send];

}

需要一些指导。谢谢..

最佳答案

将图像格式从 PNG 更改为 JPEG。

因此改变这一行

NSData *imageData = UIImagePNGRepresentation(imageV.image);

NSData *imageData = UIImageJPEGRepresentation(imageV.image,0.9);

它会解决问题...

关于ios - 在 ios 6 中使用 skp smtp 消息通过电子邮件发送超过 2 张图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13911731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com