Advertisement
Guest User

Untitled

a guest
Mar 8th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(self.emailimage)];
  2. //Create a base64 string representation of the data using NSData+Base64
  3. NSString *base64String = [imageData base64EncodedString];
  4.  
  5. //userdefaults
  6. NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
  7. // getting an NSString
  8. NSString *userName = [prefs stringForKey:@"username"];
  9. NSString *password = [prefs stringForKey:@"password"];
  10.  
  11.  
  12.  
  13. MCOSMTPSession *smtpSession = [[MCOSMTPSession alloc] init];
  14.  
  15. smtpSession.hostname =@"smtp.gmail.com";
  16. //
  17. smtpSession.port = 465;
  18.  
  19. smtpSession.username =userName;
  20. smtpSession.password =password;
  21. smtpSession.authType = MCOAuthTypeSASLPlain;
  22. smtpSession.connectionType =MCOConnectionTypeStartTLS;
  23.  
  24. MCOMessageBuilder *builder = [[MCOMessageBuilder alloc] init];
  25. MCOAddress *from1 = [MCOAddress addressWithDisplayName:@""
  26. mailbox:userName];
  27. MCOAddress *to1 = [MCOAddress addressWithDisplayName:nil
  28. mailbox:self.to.text];
  29. [[builder header] setFrom:from1];
  30. [[builder header] setTo:@[to1]];
  31. [[builder header] setSubject:self.subject.text];
  32. NSDate *now = [NSDate date];
  33.  
  34. double seconds1 = [now timeIntervalSince1970];
  35. NSNumber *seconds = [NSNumber numberWithInteger:seconds1];
  36. NSLog(@"id is=======================%@",seconds);
  37. AppDelegate *tokenD = [[UIApplication sharedApplication]delegate];
  38. NSLog(@"token in Composeviewcontroller %@",tokenD.Dtoken);
  39. NSString *htmlbody1;
  40.  
  41. htmlbody1=@"abc";
  42. [builder setHTMLBody:htmlbody1];
  43. MCOAttachment *attachment = [MCOAttachment attachmentWithContentsOfFile:self.filename];
  44. [builder addAttachment:attachment];
  45.  
  46. NSData * rfc822Data = [builder data];
  47.  
  48.  
  49. MCOSMTPSendOperation *sendOperation =
  50. [smtpSession sendOperationWithData:rfc822Data];
  51. [sendOperation start:^(NSError *error) {
  52. NSLog(@"Entered");
  53. if(error) {
  54.  
  55. NSLog(@"Error sending email: %@", error);
  56. }
  57.  
  58. else {
  59.  
  60. NSLog(@"Successfully sent email!");
  61. }
  62. }];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement