diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m index 03b378690..a1a03efe9 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher.m +++ b/ActiveSync/SOGoActiveSyncDispatcher.m @@ -3384,7 +3384,8 @@ void handle_eas_terminate(int signum) toRecipients: theRecipients sender: from withAuthenticator: authenticator - inContext: context]; + inContext: context + systemMessage: NO]; if (error) { diff --git a/Documentation/SOGoInstallationGuide.asciidoc b/Documentation/SOGoInstallationGuide.asciidoc index d61ef726e..d72b0d4da 100644 --- a/Documentation/SOGoInstallationGuide.asciidoc +++ b/Documentation/SOGoInstallationGuide.asciidoc @@ -1927,6 +1927,15 @@ To disable TLS verification for localhost domains, add Current, only `PLAIN` is supported and other values will cause the authentication to fail. +|D |SOGoSMTPMasterUserEnabled +|Enable specific SMTP user account for system e-mails (notifications, reminders, ...). Default is `NO`. + +|D |SOGoSMTPMasterUserUsername +|SMTP account username for master account (`SOGoSMTPMasterUserEnabled` enabled). + +|D |SOGoSMTPMasterUserPassword +|SMTP account password for master account (`SOGoSMTPMasterUserEnabled` enabled). + |S |WOSendMail |The path of the sendmail binary. diff --git a/SoObjects/Appointments/SOGoCalendarComponent.m b/SoObjects/Appointments/SOGoCalendarComponent.m index 7436bfe97..8124b810b 100644 --- a/SoObjects/Appointments/SOGoCalendarComponent.m +++ b/SoObjects/Appointments/SOGoCalendarComponent.m @@ -919,7 +919,8 @@ toRecipients: [NSArray arrayWithObject: email] sender: shortSenderEmail withAuthenticator: [self authenticatorInContext: context] - inContext: context]; + inContext: context + systemMessage: YES]; } } } @@ -1022,7 +1023,8 @@ toRecipients: [NSArray arrayWithObject: email] sender: [attendee rfc822Email] withAuthenticator: [self authenticatorInContext: context] - inContext: context]; + inContext: context + systemMessage: YES]; } @@ -1175,7 +1177,8 @@ toRecipients: [NSArray arrayWithObject: recipientEmail] sender: senderEmail withAuthenticator: authenticator - inContext: context]; + inContext: context + systemMessage: YES]; } if ([[self container] notifyUserOnPersonalModifications] && @@ -1192,7 +1195,8 @@ toRecipients: [NSArray arrayWithObject: recipientEmail] sender: senderEmail withAuthenticator: authenticator - inContext: context]; + inContext: context + systemMessage: YES]; [headerMap setObject: o forKey: @"to"]; } @@ -1207,7 +1211,8 @@ toRecipients: [NSArray arrayWithObject: recipientEmail] sender: senderEmail withAuthenticator: authenticator - inContext: context]; + inContext: context + systemMessage: YES]; } } diff --git a/SoObjects/Mailer/SOGoDraftObject.m b/SoObjects/Mailer/SOGoDraftObject.m index 0f55fb2b9..ad2b3a30a 100644 --- a/SoObjects/Mailer/SOGoDraftObject.m +++ b/SoObjects/Mailer/SOGoDraftObject.m @@ -2174,7 +2174,8 @@ static NSString *userAgent = nil; toRecipients: [NSArray arrayWithObject: recipient] sender: [self sender] withAuthenticator: [self authenticatorInContext: context] - inContext: context]; + inContext: context + systemMessage: NO]; if (error) return error; @@ -2199,7 +2200,8 @@ static NSString *userAgent = nil; toRecipients: [self allBareRecipients] sender: [self sender] withAuthenticator: [self authenticatorInContext: context] - inContext: context]; + inContext: context + systemMessage: NO]; } if (!error && copyToSent) diff --git a/SoObjects/Mailer/SOGoMailFolder.m b/SoObjects/Mailer/SOGoMailFolder.m index b84870e4b..12d7c7bd1 100644 --- a/SoObjects/Mailer/SOGoMailFolder.m +++ b/SoObjects/Mailer/SOGoMailFolder.m @@ -953,7 +953,8 @@ static NSInteger _compareFetchResultsByUID (id entry1, id entry2, NSDictionary * toRecipients: [NSArray arrayWithObject: recipient] sender: [[identities objectAtIndex: 0] objectForKey: @"email"] withAuthenticator: [self authenticatorInContext: context] - inContext: context]; + inContext: context + systemMessage: NO]; if (error) break; diff --git a/SoObjects/SOGo/SOGoDomainDefaults.h b/SoObjects/SOGo/SOGoDomainDefaults.h index 3be1974c3..62312a92b 100644 --- a/SoObjects/SOGo/SOGoDomainDefaults.h +++ b/SoObjects/SOGo/SOGoDomainDefaults.h @@ -60,7 +60,10 @@ - (NSString *) vacationFooterTemplateFile; - (NSString *) mailingMechanism; - (NSString *) smtpServer; -- (NSString *) smtpAuthenticationType; +- (BOOL)smtpMasterUserEnabled; +- (NSString *)smtpMasterUserUsername; +- (NSString *) smtpMasterUserPassword; +- (NSString *)smtpAuthenticationType; - (NSString *) mailSpoolPath; - (float) softQuotaRatio; - (BOOL) mailKeepDraftsAfterSend; diff --git a/SoObjects/SOGo/SOGoDomainDefaults.m b/SoObjects/SOGo/SOGoDomainDefaults.m index 41e21f53b..56079d554 100644 --- a/SoObjects/SOGo/SOGoDomainDefaults.m +++ b/SoObjects/SOGo/SOGoDomainDefaults.m @@ -292,6 +292,21 @@ return server; } +- (BOOL) smtpMasterUserEnabled +{ + return [self boolForKey: @"SOGoSMTPMasterUserEnabled"]; +} + +- (NSString *) smtpMasterUserUsername +{ + return [self stringForKey: @"SOGoSMTPMasterUserUsername"]; +} + +- (NSString *) smtpMasterUserPassword +{ + return [self stringForKey: @"SOGoSMTPMasterUserPassword"]; +} + - (NSString *) smtpAuthenticationType { return [[self stringForKey: @"SOGoSMTPAuthenticationType"] lowercaseString]; diff --git a/SoObjects/SOGo/SOGoMailer.h b/SoObjects/SOGo/SOGoMailer.h index 1c9761e2e..5b33933a0 100644 --- a/SoObjects/SOGo/SOGoMailer.h +++ b/SoObjects/SOGo/SOGoMailer.h @@ -36,6 +36,9 @@ { NSString *mailingMechanism; NSString *smtpServer; + BOOL *smtpMasterUserEnabled; + NSString *smtpMasterUserUsername; + NSString *smtpMasterUserPassword; NSString *authenticationType; } @@ -43,21 +46,24 @@ - (id) initWithDomainDefaults: (SOGoDomainDefaults *) dd; - (BOOL) requiresAuthentication; -- (NSException *) sendMailData: (NSData *) data - toRecipients: (NSArray *) recipients - sender: (NSString *) sender - withAuthenticator: (id ) authenticator - inContext: (WOContext *) woContext; -- (NSException *) sendMailAtPath: (NSString *) filename - toRecipients: (NSArray *) recipients - sender: (NSString *) sender - withAuthenticator: (id ) authenticator - inContext: (WOContext *) woContext; -- (NSException *) sendMimePart: (id ) part - toRecipients: (NSArray *) recipients - sender: (NSString *) sender - withAuthenticator: (id ) authenticator - inContext: (WOContext *) woContext; +- (NSException *)sendMailData:(NSData *)data + toRecipients:(NSArray *)recipients + sender:(NSString *)sender + withAuthenticator:(id)authenticator + inContext:(WOContext *)woContext + systemMessage:(BOOL)isSystemMessage; +- (NSException *)sendMailAtPath:(NSString *)filename + toRecipients:(NSArray *)recipients + sender:(NSString *)sender + withAuthenticator:(id)authenticator + inContext:(WOContext *)woContext + systemMessage:(BOOL)isSystemMessage; +- (NSException *)sendMimePart:(id)part + toRecipients:(NSArray *)recipients + sender:(NSString *)sender + withAuthenticator:(id)authenticator + inContext:(WOContext *)woContext + systemMessage:(BOOL)isSystemMessage; @end diff --git a/SoObjects/SOGo/SOGoMailer.m b/SoObjects/SOGo/SOGoMailer.m index ca4474dce..775005287 100644 --- a/SoObjects/SOGo/SOGoMailer.m +++ b/SoObjects/SOGo/SOGoMailer.m @@ -154,6 +154,9 @@ { ASSIGN (mailingMechanism, [dd mailingMechanism]); ASSIGN (smtpServer, [dd smtpServer]); + smtpMasterUserEnabled = [dd smtpMasterUserEnabled]; + ASSIGN (smtpMasterUserUsername, [dd smtpMasterUserUsername]); + ASSIGN (smtpMasterUserPassword, [dd smtpMasterUserPassword]); ASSIGN (authenticationType, [[dd smtpAuthenticationType] lowercaseString]); } @@ -167,6 +170,9 @@ { mailingMechanism = nil; smtpServer = nil; + smtpMasterUserEnabled = NO; + smtpMasterUserUsername = nil; + smtpMasterUserPassword = nil; authenticationType = nil; } @@ -177,6 +183,8 @@ { [mailingMechanism release]; [smtpServer release]; + [smtpMasterUserUsername release]; + [smtpMasterUserPassword release]; [authenticationType release]; [super dealloc]; } @@ -226,6 +234,7 @@ sender: (NSString *) sender withAuthenticator: (id ) authenticator inContext: (WOContext *) woContext + systemMessage: (BOOL) isSystemMessage { NSString *currentTo, *login, *password; NSMutableArray *toErrors; @@ -254,13 +263,26 @@ inDomain: [[authenticator userInContext: woContext] domain]]; password = [authenticator passwordInContext: woContext]; - if ([login length] == 0 + + if (isSystemMessage + && ![[[SOGoUserManager sharedUserManager] getEmailForUID: [[authenticator userInContext: woContext] loginInDomain]] isEqualToString: sender] + && smtpMasterUserEnabled) { + if (![client plainAuthenticateUser: smtpMasterUserUsername + withPassword: smtpMasterUserPassword]) { + result = [NSException exceptionWithHTTPStatus: 500 + reason: @"cannot send message:" + @" (smtp) authentication failure"]; + [self errorWithFormat: @"Could not connect to the SMTP server with master credentials %@", smtpServer]; + } + } else { + if ([login length] == 0 || [login isEqualToString: @"anonymous"] || ![client plainAuthenticateUser: login withPassword: password]) - result = [NSException exceptionWithHTTPStatus: 500 - reason: @"cannot send message:" - @" (smtp) authentication failure"]; + result = [NSException exceptionWithHTTPStatus: 500 + reason: @"cannot send message:" + @" (smtp) authentication failure"]; + } } else if (authenticationType && ![authenticator isKindOfClass: [SOGoEmptyAuthenticator class]]) result = [NSException @@ -327,6 +349,7 @@ sender: (NSString *) sender withAuthenticator: (id ) authenticator inContext: (WOContext *) woContext + systemMessage: (BOOL) isSystemMessage { NSException *result; @@ -399,7 +422,8 @@ toRecipients: recipients sender: [sender pureEMailAddress] withAuthenticator: authenticator - inContext: woContext]; + inContext: woContext + systemMessage: isSystemMessage]; } } @@ -411,6 +435,7 @@ sender: (NSString *) sender withAuthenticator: (id ) authenticator inContext: (WOContext *) woContext + systemMessage: (BOOL) isSystemMessage { NSData *mailData; @@ -421,7 +446,8 @@ toRecipients: recipients sender: sender withAuthenticator: authenticator - inContext: woContext]; + inContext: woContext + systemMessage: isSystemMessage]; } - (NSException *) sendMailAtPath: (NSString *) filename @@ -429,6 +455,7 @@ sender: (NSString *) sender withAuthenticator: (id ) authenticator inContext: (WOContext *) woContext + systemMessage: (BOOL) isSystemMessage { NSException *result; NSData *mailData; @@ -439,7 +466,8 @@ toRecipients: recipients sender: sender withAuthenticator: authenticator - inContext: woContext]; + inContext: woContext + systemMessage: isSystemMessage]; else result = [NSException exceptionWithHTTPStatus: 500 reason: @"cannot send message: no data" diff --git a/Tools/SOGoEAlarmsNotifier.m b/Tools/SOGoEAlarmsNotifier.m index a14e13740..0b8247891 100644 --- a/Tools/SOGoEAlarmsNotifier.m +++ b/Tools/SOGoEAlarmsNotifier.m @@ -143,7 +143,9 @@ [mailer sendMimePart: message toRecipients: [NSArray arrayWithObject: [to objectForKey: @"email"]] sender: [to objectForKey: @"email"] - withAuthenticator: staticAuthenticator inContext: nil]; + withAuthenticator: staticAuthenticator + inContext: nil + systemMessage: YES]; } - (void) _processAlarm: (iCalAlarm *) alarm diff --git a/UI/MailerUI/UIxMailView.m b/UI/MailerUI/UIxMailView.m index 7402ac045..8fd53d8c2 100644 --- a/UI/MailerUI/UIxMailView.m +++ b/UI/MailerUI/UIxMailView.m @@ -697,7 +697,8 @@ static NSString *mailETag = nil; toRecipients: [NSArray arrayWithObject: email] sender: [self _matchingIdentityEMail] withAuthenticator: [self authenticatorInContext: context] - inContext: context]) + inContext: context + systemMessage: YES]) [self _flagMessageWithMDNSent]; } diff --git a/UI/MainUI/SOGoRootPage.m b/UI/MainUI/SOGoRootPage.m index 94dcc6fc0..fdd9569ea 100644 --- a/UI/MainUI/SOGoRootPage.m +++ b/UI/MainUI/SOGoRootPage.m @@ -888,7 +888,8 @@ static const NSString *kJwtKey = @"jwt"; toRecipients: [NSArray arrayWithObjects: toEmail, nil] sender: fromEmail withAuthenticator: [SOGoEmptyAuthenticator sharedSOGoEmptyAuthenticator] - inContext: [self context]]; + inContext: [self context] + systemMessage: YES]; if (!e) { response = [self responseWithStatus: 200 diff --git a/UI/SOGoUI/SOGoACLAdvisory.m b/UI/SOGoUI/SOGoACLAdvisory.m index f80eaaeb4..3e4684e0f 100644 --- a/UI/SOGoUI/SOGoACLAdvisory.m +++ b/UI/SOGoUI/SOGoACLAdvisory.m @@ -238,7 +238,8 @@ toRecipients: [NSArray arrayWithObject: recipient] sender: from withAuthenticator: [self authenticatorInContext: context] - inContext: context]; + inContext: context + systemMessage: YES]; } @end diff --git a/UI/SOGoUI/SOGoFolderAdvisory.m b/UI/SOGoUI/SOGoFolderAdvisory.m index d7054b210..d2809fd77 100644 --- a/UI/SOGoUI/SOGoFolderAdvisory.m +++ b/UI/SOGoUI/SOGoFolderAdvisory.m @@ -208,7 +208,8 @@ toRecipients: [NSArray arrayWithObject: recipient] sender: from withAuthenticator: [self authenticatorInContext: context] - inContext: context]; + inContext: context + systemMessage: YES]; } @end