mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-14 20:08:02 +00:00
21c38b061d
# Which Problems Are Solved Send Email messages as a HTTP call to a relay, for own logic on handling different Email providers # How the Problems Are Solved Create endpoints under Email provider to manage SMTP and HTTP in the notification handlers. # Additional Changes Clean up old logic in command and query side to handle the general Email providers with deactivate, activate and remove. # Additional Context Partially closes #8270 --------- Co-authored-by: Livio Spring <livio.a@gmail.com>
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package handlers
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
"github.com/zitadel/zitadel/internal/notification/channels/email"
|
|
"github.com/zitadel/zitadel/internal/notification/channels/smtp"
|
|
"github.com/zitadel/zitadel/internal/notification/channels/webhook"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
// GetSMTPConfig reads the iam SMTP provider config
|
|
func (n *NotificationQueries) GetActiveEmailConfig(ctx context.Context) (*email.Config, error) {
|
|
config, err := n.SMTPConfigActive(ctx, authz.GetInstance(ctx).InstanceID())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
provider := &email.Provider{
|
|
ID: config.ID,
|
|
Description: config.Description,
|
|
}
|
|
if config.SMTPConfig != nil {
|
|
password, err := crypto.DecryptString(config.SMTPConfig.Password, n.SMTPPasswordCrypto)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &email.Config{
|
|
ProviderConfig: provider,
|
|
SMTPConfig: &smtp.Config{
|
|
From: config.SMTPConfig.SenderAddress,
|
|
FromName: config.SMTPConfig.SenderName,
|
|
ReplyToAddress: config.SMTPConfig.ReplyToAddress,
|
|
Tls: config.SMTPConfig.TLS,
|
|
SMTP: smtp.SMTP{
|
|
Host: config.SMTPConfig.Host,
|
|
User: config.SMTPConfig.User,
|
|
Password: password,
|
|
},
|
|
},
|
|
}, nil
|
|
}
|
|
if config.HTTPConfig != nil {
|
|
return &email.Config{
|
|
ProviderConfig: provider,
|
|
WebhookConfig: &webhook.Config{
|
|
CallURL: config.HTTPConfig.Endpoint,
|
|
Method: http.MethodPost,
|
|
Headers: nil,
|
|
},
|
|
}, nil
|
|
}
|
|
return nil, zerrors.ThrowNotFound(err, "QUERY-KPQleOckOV", "Errors.SMTPConfig.NotFound")
|
|
}
|