iOS開發筆記--iOS後台發送郵件

來源:互聯網
上載者:User

標籤:

skpsmtpmessage 是ios第三方後台發送郵件庫 https://github.com/jetseven/skpsmtpmessage.git

原文地址:http://www.cnblogs.com/U-tansuo/p/ios_send_email.html

-(void)statrUpLoad:(id)sender
{
    SKPSMTPMessage *testSend = [[SKPSMTPMessage alloc]init];
    testSend.fromEmail = @"發件郵箱";
    testSend.toEmail = @"收件郵箱";
    testSend.relayHost = @"smtp.163.com";
    testSend.requiresAuth = YES;
    testSend.login = @"使用者名稱;
    testSend.pass = @"密碼;
    testSend.subject = [NSString stringWithCString:"測試" encoding:NSUTF8StringEncoding];
    testSend.ccEmail = @"抄送郵件";
    testSend.wantsSecure = YES;
    testSend.delegate = self;
    
    NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey,
                               @"This is a tést messåge.",kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];
    
    NSString *vcfPath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"vcf"];
    NSData *vcfData = [NSData dataWithContentsOfFile:vcfPath];
    //通訊錄
    NSDictionary *vcfPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/directory;\r\n\tx-unix-mode=0644;\r\n\tname=\"test.vcf\"",kSKPSMTPPartContentTypeKey,
                             @"attachment;\r\n\tfilename=\"test.vcf\"",kSKPSMTPPartContentDispositionKey,[vcfData encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil];
    //發圖片附件
      NSString *imgPath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"jpg"];
    NSData *imgData = [NSData dataWithContentsOfFile:imgPath];
    NSDictionary *imagePart = [NSDictionary dictionaryWithObjectsAndKeys:@"image/jpg;\r\n\tx-unix-mode=0644;\r\n\tname=\"test.jpg\"",kSKPSMTPPartContentTypeKey,
                               @"attachment;\r\n\tfilename=\"test.jpg\"",kSKPSMTPPartContentDispositionKey,[imgData encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil];
    //發視頻附件
    //attach video
    NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mov"];
    NSData *videoData = [NSData dataWithContentsOfFile: videoPath];
    NSDictionary *videoPart = [NSDictionary dictionaryWithObjectsAndKeys:@"video/quicktime;\r\n\tx-unix-mode=0644;\r\n\tname=\"video.mov\"",kSKPSMTPPartContentTypeKey,
                               @"attachment;\r\n\tfilename=\"video.mov\"",kSKPSMTPPartContentDispositionKey,[videoData encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil];
    
    testMsg.parts = [NSArray arrayWithObjects:plainPart,vcfPart, imagePart, videoPart, nil];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [testSend send];
    });
}

iOS開發筆記--iOS後台發送郵件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.