Skip to content
Permalink
Browse files

Squashed commit of the following:

commit e8927270167adb417ba1e0d819a619112e315cbb
Merge: bf46ac0 0ca96c3
Author: Joe Keenan <joe@flyingdiver.com>
Date:   Mon Sep 2 20:05:04 2013 -0400

    Merge branch 'refs/heads/feature-mailcore' into bugfix-0.9.2

commit 0ca96c34f78f18dd1290f658425ab7ed356b6f60
Author: Joe Keenan <joe@flyingdiver.com>
Date:   Mon Sep 2 15:46:57 2013 -0400

    Added completion block to SMTP validation

    removed redundant code in Preferences

commit bf46ac0b48c8a425bbfa1d1ab7b2615a2c8d94be
Author: Joe Keenan <joe@flyingdiver.com>
Date:   Mon Sep 2 13:11:16 2013 -0400

    Stoker code bug fixes

    Fix to pick up temp target changes on Stoker
    misc code cleanup
    Fixed connection completion handlers - delayed quit working

commit ed6706028c416aae9c71d3b405174c088354f734
Author: Joe Keenan <joe@flyingdiver.com>
Date:   Sun Sep 1 21:30:05 2013 -0400

    More Email updates

    Added SMTP settings to Preferences
    Added Keychain Support for SMTP & Prowl
    Added help button links to Preferences

commit 70fa1245449f4d48bb41bcd8c6db5d2c7b759b34
Merge: 502d5ce 45f8cdb
Author: Joe Keenan <joe@flyingdiver.com>
Date:   Sun Sep 1 14:57:46 2013 -0400

    Merge branch 'refs/heads/master' into feature-mailcore

    Conflicts:
    	StokerX-Info.plist
    	StokerX.xcodeproj/project.pbxproj
    	StokerXAppDelegate.h

commit 45f8cdb2e5ce2a59676624b2c70a0f038240e93a
Author: Joe Keenan <joe@flyingdiver.com>
Date:   Sat Aug 31 08:41:07 2013 -0400

    0.9.2 fixes

    Deleted errant debug message
    added delay to JSON request retry
    fixed plot annotation compiler warnings with StokerPlotControllerDelegate
    Moved Prowl API key from Preferences to KeyChain

commit 502d5ce66627459dbb49a8e438a4c6f904498a58
Author: Joe Keenan <joe@flyingdiver.com>
Date:   Sat Aug 31 23:22:28 2013 -0400

    MailCore2 replacing Mail.app ScriptingBridge

    Removed all the Mail.app SB code
    Added MailCore2 project references
    initial code for sending emails and verifying smtp setup

commit 4a6912acb987dea572cacef23494611715cb1dee
Author: Joe Keenan <joe@flyingdiver.com>
Date:   Sat Aug 31 08:41:07 2013 -0400

    0.9.2 fixes

    Deleted errant debug message
    added delay to JSON request retry
    fixed plot annotation compiler warnings with StokerPlotControllerDelegate
  • Loading branch information...
FlyingDiver committed Aug 31, 2013
1 parent d6a7e46 commit 872a35995e466e9c5dc966f616c92e0a6779f05f
@@ -7,10 +7,14 @@
//

#import <Cocoa/Cocoa.h>
#import "MailCore/MailCore.h"


@interface EmailSender: NSObject

- (void)sendEmailMessage:(NSString *)message to: (NSString *) recipient;
- (void) sendEmailMessage:(NSString *)message to: (NSString *) recipient;
- (void) validateSMTPWithCompletionHandler:(void (^)(BOOL))handler;

//@property (copy) void (^validateSMTPCompletionBlock)(BOOL);

@end
@@ -8,54 +8,65 @@

#import <CoreServices/CoreServices.h>
#import "EmailSender.h"
#import "Mail.h"
#import "PreferencesController.h"

@implementation EmailSender

- (id)eventDidFail:(const AppleEvent *)event withError:(NSError *)error
{
NSLog(@"Stoker EmailSender Error: %@", [error localizedDescription]);
- (void)sendEmailMessage:(NSString *) messageBody to: (NSString *) recipient
{
MCOSMTPSession *smtpSession = [[MCOSMTPSession alloc] init];

smtpSession.hostname = [[NSUserDefaults standardUserDefaults] stringForKey: kSMTPServerKey];
smtpSession.port = [[NSUserDefaults standardUserDefaults] integerForKey: kSMTPPortKey];
smtpSession.connectionType = [[NSUserDefaults standardUserDefaults] integerForKey: kConnectionTypeKey];
smtpSession.authType =[[NSUserDefaults standardUserDefaults] integerForKey: kAuthTypeKey];

NSArray *smtpAccounts = [SSKeychain accountsForService: kStokerSMTPLogin];
smtpSession.username = [[smtpAccounts objectAtIndex: 0] objectForKey: @"acct"];
smtpSession.password = [SSKeychain passwordForService: kStokerSMTPLogin account: smtpSession.username];

return nil;
MCOMessageBuilder * builder = [[MCOMessageBuilder alloc] init];

[[builder header] setFrom:[MCOAddress addressWithDisplayName:nil mailbox: recipient]];

[[builder header] setTo: [NSArray arrayWithObject: [MCOAddress addressWithMailbox: recipient]]];

[[builder header] setSubject: @"StokerX Notification"];

[builder setTextBody: messageBody];

MCOSMTPSendOperation *sendOperation = [smtpSession sendOperationWithData: [builder data]];
[sendOperation start:^(NSError *error)
{
if(error)
{
NSLog(@"EmailSender sendEmailMessage: error: code = %ld, domain = %@\nuserInfo = %@", (long)error.code, error.domain, error.userInfo);
}
}];
}

- (void)sendEmailMessage:(NSString *) messageBody to: (NSString *) recipient;
- (void) validateSMTPWithCompletionHandler:(void (^)(BOOL))handler
{
MailApplication *mail = [SBApplication applicationWithBundleIdentifier:@"com.apple.Mail"];
mail.delegate = (id) self;

MailOutgoingMessage *emailMessage = [[[mail classForScriptingClass:@"outgoing message"] alloc] initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
@"StokerX Notification", @"subject",
messageBody, @"content",
nil]];

[[mail outgoingMessages] addObject: emailMessage];

emailMessage.sender = recipient;
emailMessage.visible = NO;

if ( [mail lastError] != nil )
{
[emailMessage release];
return;
}

MailToRecipient *theRecipient = [[[mail classForScriptingClass:@"to recipient"] alloc] initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
recipient, @"address",
nil]];
[emailMessage.toRecipients addObject: theRecipient];
[theRecipient release];

if ( [mail lastError] != nil )
{
[emailMessage release];
return;
}
MCOSMTPSession *smtpSession = [[MCOSMTPSession alloc] init];

[emailMessage send];
[emailMessage release];
smtpSession.hostname = [[NSUserDefaults standardUserDefaults] stringForKey: kSMTPServerKey];
smtpSession.port = [[NSUserDefaults standardUserDefaults] integerForKey: kSMTPPortKey];
smtpSession.connectionType = [[NSUserDefaults standardUserDefaults] integerForKey: kConnectionTypeKey];
smtpSession.authType =[[NSUserDefaults standardUserDefaults] integerForKey: kAuthTypeKey];

NSArray *smtpAccounts = [SSKeychain accountsForService: kStokerSMTPLogin];
smtpSession.username = [[smtpAccounts objectAtIndex: 0] objectForKey: @"acct"];
smtpSession.password = [SSKeychain passwordForService: kStokerSMTPLogin account: smtpSession.username];

MCOSMTPOperation *checkOperation = [smtpSession checkAccountOperationWithFrom: [MCOAddress addressWithMailbox: @"joe@flyingdiver.com"]];
[checkOperation start:^(NSError *error)
{
if(error)
handler(FALSE);
else
handler(TRUE);
}];
}


@end
Oops, something went wrong.

0 comments on commit 872a359

Please sign in to comment.
You can’t perform that action at this time.