Skip to content

Commit

Permalink
feat(alarms): Add possibility to use SMTP master account for system a…
Browse files Browse the repository at this point in the history
…larms. Fixes #5565.
  • Loading branch information
WoodySlum committed Feb 16, 2023
1 parent 2c6f522 commit 8001e3f
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 37 deletions.
3 changes: 2 additions & 1 deletion ActiveSync/SOGoActiveSyncDispatcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -3384,7 +3384,8 @@ - (NSException *) _sendMail: (NSData *) theMail
toRecipients: theRecipients
sender: from
withAuthenticator: authenticator
inContext: context];
inContext: context
systemMessage: NO];

if (error)
{
Expand Down
9 changes: 9 additions & 0 deletions Documentation/SOGoInstallationGuide.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 10 additions & 5 deletions SoObjects/Appointments/SOGoCalendarComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,8 @@ - (void) sendEMailUsingTemplateNamed: (NSString *) newPageName
toRecipients: [NSArray arrayWithObject: email]
sender: shortSenderEmail
withAuthenticator: [self authenticatorInContext: context]
inContext: context];
inContext: context
systemMessage: YES];
}
}
}
Expand Down Expand Up @@ -1022,7 +1023,8 @@ - (void) _sendIMIPReplyForEvent: (iCalRepeatableEntityObject *) event
toRecipients: [NSArray arrayWithObject: email]
sender: [attendee rfc822Email]
withAuthenticator: [self authenticatorInContext: context]
inContext: context];
inContext: context
systemMessage: YES];
}


Expand Down Expand Up @@ -1175,7 +1177,8 @@ - (void) sendReceiptEmailForObject: (iCalEntityObject *) object
toRecipients: [NSArray arrayWithObject: recipientEmail]
sender: senderEmail
withAuthenticator: authenticator
inContext: context];
inContext: context
systemMessage: YES];
}

if ([[self container] notifyUserOnPersonalModifications] &&
Expand All @@ -1192,7 +1195,8 @@ - (void) sendReceiptEmailForObject: (iCalEntityObject *) object
toRecipients: [NSArray arrayWithObject: recipientEmail]
sender: senderEmail
withAuthenticator: authenticator
inContext: context];
inContext: context
systemMessage: YES];

[headerMap setObject: o forKey: @"to"];
}
Expand All @@ -1207,7 +1211,8 @@ - (void) sendReceiptEmailForObject: (iCalEntityObject *) object
toRecipients: [NSArray arrayWithObject: recipientEmail]
sender: senderEmail
withAuthenticator: authenticator
inContext: context];
inContext: context
systemMessage: YES];
}

}
Expand Down
6 changes: 4 additions & 2 deletions SoObjects/Mailer/SOGoDraftObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -2174,7 +2174,8 @@ - (NSException *) sendMailAndCopyToSent: (BOOL) copyToSent
toRecipients: [NSArray arrayWithObject: recipient]
sender: [self sender]
withAuthenticator: [self authenticatorInContext: context]
inContext: context];
inContext: context
systemMessage: NO];

if (error)
return error;
Expand All @@ -2199,7 +2200,8 @@ - (NSException *) sendMailAndCopyToSent: (BOOL) copyToSent
toRecipients: [self allBareRecipients]
sender: [self sender]
withAuthenticator: [self authenticatorInContext: context]
inContext: context];
inContext: context
systemMessage: NO];
}

if (!error && copyToSent)
Expand Down
3 changes: 2 additions & 1 deletion SoObjects/Mailer/SOGoMailFolder.m
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,8 @@ - (WOResponse *) markMessagesAsJunkOrNotJunk: (NSArray *) uids
toRecipients: [NSArray arrayWithObject: recipient]
sender: [[identities objectAtIndex: 0] objectForKey: @"email"]
withAuthenticator: [self authenticatorInContext: context]
inContext: context];
inContext: context
systemMessage: NO];

if (error)
break;
Expand Down
5 changes: 4 additions & 1 deletion SoObjects/SOGo/SOGoDomainDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions SoObjects/SOGo/SOGoDomainDefaults.m
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,21 @@ - (NSString *) smtpServer
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];
Expand Down
36 changes: 21 additions & 15 deletions SoObjects/SOGo/SOGoMailer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,34 @@
{
NSString *mailingMechanism;
NSString *smtpServer;
BOOL *smtpMasterUserEnabled;
NSString *smtpMasterUserUsername;
NSString *smtpMasterUserPassword;
NSString *authenticationType;
}

+ (SOGoMailer *) mailerWithDomainDefaults: (SOGoDomainDefaults *) dd;

- (id) initWithDomainDefaults: (SOGoDomainDefaults *) dd;
- (BOOL) requiresAuthentication;
- (NSException *) sendMailData: (NSData *) data
toRecipients: (NSArray *) recipients
sender: (NSString *) sender
withAuthenticator: (id <SOGoAuthenticator>) authenticator
inContext: (WOContext *) woContext;
- (NSException *) sendMailAtPath: (NSString *) filename
toRecipients: (NSArray *) recipients
sender: (NSString *) sender
withAuthenticator: (id <SOGoAuthenticator>) authenticator
inContext: (WOContext *) woContext;
- (NSException *) sendMimePart: (id <NGMimePart>) part
toRecipients: (NSArray *) recipients
sender: (NSString *) sender
withAuthenticator: (id <SOGoAuthenticator>) authenticator
inContext: (WOContext *) woContext;
- (NSException *)sendMailData:(NSData *)data
toRecipients:(NSArray *)recipients
sender:(NSString *)sender
withAuthenticator:(id<SOGoAuthenticator>)authenticator
inContext:(WOContext *)woContext
systemMessage:(BOOL)isSystemMessage;
- (NSException *)sendMailAtPath:(NSString *)filename
toRecipients:(NSArray *)recipients
sender:(NSString *)sender
withAuthenticator:(id<SOGoAuthenticator>)authenticator
inContext:(WOContext *)woContext
systemMessage:(BOOL)isSystemMessage;
- (NSException *)sendMimePart:(id<NGMimePart>)part
toRecipients:(NSArray *)recipients
sender:(NSString *)sender
withAuthenticator:(id<SOGoAuthenticator>)authenticator
inContext:(WOContext *)woContext
systemMessage:(BOOL)isSystemMessage;

@end

Expand Down
42 changes: 35 additions & 7 deletions SoObjects/SOGo/SOGoMailer.m
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ - (id) initWithDomainDefaults: (SOGoDomainDefaults *) dd
{
ASSIGN (mailingMechanism, [dd mailingMechanism]);
ASSIGN (smtpServer, [dd smtpServer]);
smtpMasterUserEnabled = [dd smtpMasterUserEnabled];
ASSIGN (smtpMasterUserUsername, [dd smtpMasterUserUsername]);
ASSIGN (smtpMasterUserPassword, [dd smtpMasterUserPassword]);
ASSIGN (authenticationType,
[[dd smtpAuthenticationType] lowercaseString]);
}
Expand All @@ -167,6 +170,9 @@ - (id) init
{
mailingMechanism = nil;
smtpServer = nil;
smtpMasterUserEnabled = NO;
smtpMasterUserUsername = nil;
smtpMasterUserPassword = nil;
authenticationType = nil;
}

Expand All @@ -177,6 +183,8 @@ - (void) dealloc
{
[mailingMechanism release];
[smtpServer release];
[smtpMasterUserUsername release];
[smtpMasterUserPassword release];
[authenticationType release];
[super dealloc];
}
Expand Down Expand Up @@ -226,6 +234,7 @@ - (NSException *) _smtpSendData: (NSData *) mailData
sender: (NSString *) sender
withAuthenticator: (id <SOGoAuthenticator>) authenticator
inContext: (WOContext *) woContext
systemMessage: (BOOL) isSystemMessage
{
NSString *currentTo, *login, *password;
NSMutableArray *toErrors;
Expand Down Expand Up @@ -254,13 +263,26 @@ - (NSException *) _smtpSendData: (NSData *) mailData
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
Expand Down Expand Up @@ -327,6 +349,7 @@ - (NSException *) sendMailData: (NSData *) data
sender: (NSString *) sender
withAuthenticator: (id <SOGoAuthenticator>) authenticator
inContext: (WOContext *) woContext
systemMessage: (BOOL) isSystemMessage
{
NSException *result;

Expand Down Expand Up @@ -399,7 +422,8 @@ - (NSException *) sendMailData: (NSData *) data
toRecipients: recipients
sender: [sender pureEMailAddress]
withAuthenticator: authenticator
inContext: woContext];
inContext: woContext
systemMessage: isSystemMessage];
}
}

Expand All @@ -411,6 +435,7 @@ - (NSException *) sendMimePart: (id <NGMimePart>) part
sender: (NSString *) sender
withAuthenticator: (id <SOGoAuthenticator>) authenticator
inContext: (WOContext *) woContext
systemMessage: (BOOL) isSystemMessage
{
NSData *mailData;

Expand All @@ -421,14 +446,16 @@ - (NSException *) sendMimePart: (id <NGMimePart>) part
toRecipients: recipients
sender: sender
withAuthenticator: authenticator
inContext: woContext];
inContext: woContext
systemMessage: isSystemMessage];
}

- (NSException *) sendMailAtPath: (NSString *) filename
toRecipients: (NSArray *) recipients
sender: (NSString *) sender
withAuthenticator: (id <SOGoAuthenticator>) authenticator
inContext: (WOContext *) woContext
systemMessage: (BOOL) isSystemMessage
{
NSException *result;
NSData *mailData;
Expand All @@ -439,7 +466,8 @@ - (NSException *) sendMailAtPath: (NSString *) filename
toRecipients: recipients
sender: sender
withAuthenticator: authenticator
inContext: woContext];
inContext: woContext
systemMessage: isSystemMessage];
else
result = [NSException exceptionWithHTTPStatus: 500
reason: @"cannot send message: no data"
Expand Down
4 changes: 3 additions & 1 deletion Tools/SOGoEAlarmsNotifier.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ - (void) _sendMessageWithHeaders: (NGMutableHashMap *) headers
[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
Expand Down
3 changes: 2 additions & 1 deletion UI/MailerUI/UIxMailView.m
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,8 @@ - (void) _sendEMailReceiptTo: (NSString *) email
toRecipients: [NSArray arrayWithObject: email]
sender: [self _matchingIdentityEMail]
withAuthenticator: [self authenticatorInContext: context]
inContext: context])
inContext: context
systemMessage: YES])
[self _flagMessageWithMDNSent];
}

Expand Down
3 changes: 2 additions & 1 deletion UI/MainUI/SOGoRootPage.m
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,8 @@ - (WOResponse *) passwordRecoveryEmailAction
toRecipients: [NSArray arrayWithObjects: toEmail, nil]
sender: fromEmail
withAuthenticator: [SOGoEmptyAuthenticator sharedSOGoEmptyAuthenticator]
inContext: [self context]];
inContext: [self context]
systemMessage: YES];

if (!e) {
response = [self responseWithStatus: 200
Expand Down
3 changes: 2 additions & 1 deletion UI/SOGoUI/SOGoACLAdvisory.m
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ - (void) send
toRecipients: [NSArray arrayWithObject: recipient]
sender: from
withAuthenticator: [self authenticatorInContext: context]
inContext: context];
inContext: context
systemMessage: YES];
}

@end
Expand Down
3 changes: 2 additions & 1 deletion UI/SOGoUI/SOGoFolderAdvisory.m
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ - (void) send
toRecipients: [NSArray arrayWithObject: recipient]
sender: from
withAuthenticator: [self authenticatorInContext: context]
inContext: context];
inContext: context
systemMessage: YES];
}

@end
Expand Down

0 comments on commit 8001e3f

Please sign in to comment.