Skip to content
Browse files

Merge pull request #93 from DanGonz/master

Fix to CTSMTPAsyncConnection so that it can also use SMTP with SSL on port 465.
  • Loading branch information...
2 parents 3a5e94a + 73380c7 commit e22a886fbeddbc8aa5d49510c5e64e9ed830bb26 @mronge mronge committed Apr 4, 2013
Showing with 25 additions and 15 deletions.
  1. +5 −5 Source/CTSMTPAsyncConnection.h
  2. +20 −10 Source/CTSMTPAsyncConnection.m
View
10 Source/CTSMTPAsyncConnection.h
@@ -47,7 +47,7 @@
@class CTSMTP;
-@interface CTSMTPAsyncConnection : NSObject
+@interface CTSMTPAsyncConnection : NSObject
{
CTSMTP* mSMTPObj;
mailsmtp* mSMTP;
@@ -63,11 +63,11 @@
@property (retain) CTCoreMessage* message;
@property (readonly) CTSMTPAsyncStatus status;
-- (id)initWithServer:(NSString *)aServer
+- (id)initWithServer:(NSString *)aServer
username:(NSString *)aUsername
- password:(NSString *)aPassword
- port:(unsigned int)aPort
- useTLS:(BOOL)aTls
+ password:(NSString *)aPassword
+ port:(unsigned int)aPort
+ connectionType:(CTSMTPConnectionType)connectionType
useAuth:(BOOL)aAuth
delegate:(id<CTSMTPConnectionDelegate>)aDelegate;
View
30 Source/CTSMTPAsyncConnection.m
@@ -73,7 +73,7 @@ - (id)initWithServer:(NSString *)aServer
username:(NSString *)aUsername
password:(NSString *)aPassword
port:(unsigned int)aPort
- useTLS:(BOOL)aTls
+ connectionType:(CTSMTPConnectionType)connectionType
useAuth:(BOOL)aAuth
delegate:(id <CTSMTPConnectionDelegate>)aDelegate {
@@ -90,7 +90,7 @@ - (id)initWithServer:(NSString *)aServer
aUsername, @"username",
aPassword, @"password",
[NSNumber numberWithInt:aPort], @"port",
- [NSNumber numberWithBool:aTls], @"tls",
+ [NSNumber numberWithInt:connectionType], @"connectionType",
[NSNumber numberWithBool:aAuth], @"auth", nil] retain];
//save clients from themselves (they could be leaking us - no dealloc)
@@ -169,9 +169,19 @@ - (void)sendMailThread {
mSMTPObj = [[CTESMTP alloc] initWithResource:mSMTP];
NSDictionary *theSettings = self.serverSettings;
-
- success = [mSMTPObj connectToServer:[theSettings objectForKey:@"server"]
- port:[[theSettings objectForKey:@"port"] unsignedIntValue]];
+ CTSMTPConnectionType connectionType = [[theSettings objectForKey:@"connectionType"] unsignedIntValue];
+ NSString* server = [theSettings objectForKey:@"server"];
+ unsigned int port = [[theSettings objectForKey:@"port"] unsignedIntValue];
+ BOOL auth = [[theSettings objectForKey:@"auth"] boolValue];
+ NSString* username = [theSettings objectForKey:@"username"];
+ NSString* password = [theSettings objectForKey:@"password"];
+
+ if (connectionType == CTSMTPConnectionTypeStartTLS || connectionType == CTSMTPConnectionTypePlain) {
+ success = [mSMTPObj connectToServer:server port:port];
+ } else if (connectionType == CTSMTPConnectionTypeTLS) {
+ success = [mSMTPObj connectWithTlsToServer:server port:port];
+ }
+
if (!success) {
goto error;
}
@@ -184,16 +194,16 @@ - (void)sendMailThread {
goto error;
}
}
- if ([(NSNumber *) [theSettings objectForKey:@"tls"] boolValue]) {
+
+ if (connectionType == CTSMTPConnectionTypeStartTLS) {
success = [mSMTPObj startTLS];
if (!success) {
goto error;
}
}
- if ([(NSNumber *) [theSettings objectForKey:@"auth"] boolValue]) {
- success = [mSMTPObj authenticateWithUsername:[theSettings objectForKey:@"username"]
- password:[theSettings objectForKey:@"password"]
- server:[theSettings objectForKey:@"server"]];
+
+ if (auth) {
+ success = [mSMTPObj authenticateWithUsername:username password:password server:server];
if (!success) {
goto error;
}

0 comments on commit e22a886

Please sign in to comment.
Something went wrong with that request. Please try again.