Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // build session with credentials and authentication
- NSString *smtpHostname = @"mrint.1and1.com";
- NSUInteger smtpPort = 587;
- NSString *smtpUsername = @"<intranetuser>";
- NSString *smtpPassword = @"<password>";
- NSString *fromEmail = @"<email?";
- NSString *fromDisplayname = @"Peter Breitling";
- MCOSMTPSession *smtpSession = [[MCOSMTPSession alloc] init];
- smtpSession.checkCertificateEnabled = NO;
- smtpSession.hostname = smtpHostname;
- smtpSession.port = (unsigned int) smtpPort;
- smtpSession.username = smtpUsername;
- smtpSession.password = smtpPassword;
- smtpSession.connectionType = MCOConnectionTypeStartTLS;
- //smtpSession.authType = MCOAuthTypeSASLPlain;
- //smtpSession.authType = MCOAuthTypeSASLNone;
- // build from
- MCOMessageBuilder * builder = [[MCOMessageBuilder alloc] init];
- [[builder header] setFrom:[MCOAddress addressWithDisplayName:fromDisplayname mailbox:fromEmail]];
- //[[builder header] setFrom:[MCOAddress addressWithRFC822String:fromEmail]];
- // build to, cc and bcc adresses
- NSMutableArray *to = [[NSMutableArray alloc] init];
- for (NSString *email in [mail sortedToMailContacts])
- {
- [to addObject:[MCOAddress addressWithMailbox:email]];
- }
- [[builder header] setTo:to];
- NSMutableArray *cc = [[NSMutableArray alloc] init];
- for (NSString *email in [mail sortedCcMailContacts])
- {
- [cc addObject:[MCOAddress addressWithMailbox:email]];
- }
- [[builder header] setCc:cc];
- NSMutableArray *bcc = [[NSMutableArray alloc] init];
- for (NSString *email in [mail sortedBccMailContacts])
- {
- [bcc addObject:[MCOAddress addressWithMailbox:email]];
- }
- [[builder header] setBcc:bcc];
- // subject, text- & html-body
- [[builder header] setSubject:mail.subject];
- builder.textBody = mail.textBody.content;
- builder.htmlBody = htmlBody;
- // attachments
- // MCOAttachment *attachment = [MCOAttachment attachmentWithContentsOfFile:path];
- // [builder addAttachment:attachment];
- NSData * rfc822Data = [builder data];
- smtpSession.connectionLogger = ^(void * connectionID, MCOConnectionLogType type, NSData * data){
- NSLog(@"smtp session[%li] %@", (long)type, [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
- };
- MCOSMTPSendOperation *sendOperation = [smtpSession sendOperationWithData:rfc822Data];
- [sendOperation start:^(NSError *error) {
- if(error) {
- NSLog(@"Error sending email:%@", error);
- } else {
- NSLog(@"Successfully sent email!");
- }
- }];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement