feat(alarms): Add possibility to use SMTP master account for system alarms. Fixes #5565.

This commit is contained in:
smizrahi
2023-02-16 18:47:54 +01:00
parent 2c6f5225d4
commit 8001e3f6ab
14 changed files with 113 additions and 37 deletions

View File

@@ -3384,7 +3384,8 @@ void handle_eas_terminate(int signum)
toRecipients: theRecipients
sender: from
withAuthenticator: authenticator
inContext: context];
inContext: context
systemMessage: NO];
if (error)
{

View File

@@ -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.

View File

@@ -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];
}
}

View File

@@ -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)

View File

@@ -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;

View File

@@ -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;

View File

@@ -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];

View File

@@ -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 <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

View File

@@ -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 <SOGoAuthenticator>) authenticator
inContext: (WOContext *) woContext
systemMessage: (BOOL) isSystemMessage
{
NSString *currentTo, *login, *password;
NSMutableArray *toErrors;
@@ -254,6 +263,18 @@
inDomain: [[authenticator userInContext: woContext] domain]];
password = [authenticator passwordInContext: woContext];
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
@@ -262,6 +283,7 @@
reason: @"cannot send message:"
@" (smtp) authentication failure"];
}
}
else if (authenticationType && ![authenticator isKindOfClass: [SOGoEmptyAuthenticator class]])
result = [NSException
exceptionWithHTTPStatus: 500
@@ -327,6 +349,7 @@
sender: (NSString *) sender
withAuthenticator: (id <SOGoAuthenticator>) 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 <SOGoAuthenticator>) 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 <SOGoAuthenticator>) 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"

View File

@@ -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

View File

@@ -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];
}

View File

@@ -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

View File

@@ -238,7 +238,8 @@
toRecipients: [NSArray arrayWithObject: recipient]
sender: from
withAuthenticator: [self authenticatorInContext: context]
inContext: context];
inContext: context
systemMessage: YES];
}
@end

View File

@@ -208,7 +208,8 @@
toRecipients: [NSArray arrayWithObject: recipient]
sender: from
withAuthenticator: [self authenticatorInContext: context]
inContext: context];
inContext: context
systemMessage: YES];
}
@end