IOS 开发中发送e-mail的几种方法总结

2020-01-18 21:23:09王冬梅

3、我们可以根据自己的UI设计需求来定制相应的视图以适应整体的设计。可以使用比较有名的开源SMTP协议来实现。   

在SKPSMTPMessage类中,并没有对视图进行任何的要求,它提供的都是数据层级的处理,你之需要定义好相应的发送要求就可以实现邮件发送了。至于是以什么样的方式获取这些信息,就可以根据软件的需求来确定交互方式和视图样式了。  


    SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init]; 
  testMsg.fromEmail = @"test@gmail.com"; 
  testMsg.toEmail =@"to@gmail.com"; 
  testMsg.relayHost = @"smtp.gmail.com"; 
  testMsg.requiresAuth = YES; 
  testMsg.login = @"test@gmail.com"; 
  testMsg.pass = @"test"; 
  testMsg.subject = [NSString stringWithCString:"测试" encoding:NSUTF8StringEncoding]; 
  testMsg.bccEmail = @"bcc@gmail.com"; 
  testMsg.wantsSecure = YES; // smtp.gmail.com doesn't work without TLS! 
 
  // Only do this for self-signed certs! 
  // testMsg.validateSSLChain = NO; 
  testMsg.delegate = self; 
 
  NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey, 
         [NSString stringWithCString:"测试正文" encoding:NSUTF8StringEncoding],kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil]; 
 
   NSString *vcfPath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"vcf"]; 
   NSData *vcfData = [NSData dataWithContentsOfFile:vcfPath]; 
 
   NSDictionary *vcfPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/directory;rntx-unix-mode=0644;rntname="test.vcf"",kSKPSMTPPartContentTypeKey, 
          @"attachment;rntfilename="test.vcf"",kSKPSMTPPartContentDispositionKey,[vcfData encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil]; 
 
  testMsg.parts = [NSArray arrayWithObjects:plainPart,vcfPart,nil]; 
 
  [testMsg send]; 
//该类也提供了相应的Delegate方法来让你更好的获知发送的状态. 
 
-(void)messageSent:(SKPSMTPMessage *)message; 
-(void)messageFailed:(SKPSMTPMessage *)message error:(NSError *)error; 

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!


注:相关教程知识阅读请移步到IOS开发频道。