Project

General

Profile

Milestone #79

Updated by Daniele Cruciani about 1 month ago

Yes, absolutely! You can configure your Redmine instance to use this Postfix mail server as its SMTP relay. Here's how to set it up: 

 ## 1. **First, Update Redmine Configuration** 

 Create or update a ConfigMap for Redmine's email configuration: 

 ```yaml 
 # redmine-email-config.yaml 
 apiVersion: v1 
 kind: ConfigMap 
 metadata: 
   name: redmine-email-config 
 data: 
   configuration.yml: | 
     default: 
       email_delivery: 
         delivery_method: :smtp 
         smtp_settings: 
           address: "postfix"    # Postfix service name in Kubernetes 
           port: 587 
           domain: "yourdomain.com" 
           authentication: :none    # No auth to Postfix (internal traffic) 
           enable_starttls_auto: false    # Postfix handles TLS to Gmail 
           openssl_verify_mode: 'none'    # For self-signed certs if needed 
 ``` 

 ## 2. **Mount the Configuration in Redmine Deployment** 

 Update your Redmine deployment to use this ConfigMap: 

 ```yaml 
 # redmine-deployment-patch.yaml 
 apiVersion: apps/v1 
 kind: Deployment 
 metadata: 
   name: redmine 
 spec: 
   template: 
     spec: 
       containers: 
       - name: redmine 
         volumeMounts: 
         - name: email-config 
           mountPath: /usr/src/redmine/config/configuration.yml 
           subPath: configuration.yml 
       volumes: 
       - name: email-config 
         configMap: 
           name: redmine-email-config 
 ``` 

 ## 3. **Alternative: Using Redmine Environment Variables** 

 If your Redmine image supports environment variables for email configuration: 

 ```yaml 
 # redmine-deployment-env.yaml 
 apiVersion: apps/v1 
 kind: Deployment 
 metadata: 
   name: redmine 
 spec: 
   template: 
     spec: 
       containers: 
       - name: redmine 
         env: 
         - name: REDMINE_EMAIL_DELIVERY_METHOD 
           value: "smtp" 
         - name: REDMINE_SMTP_HOST 
           value: "postfix"    # Kubernetes service name 
         - name: REDMINE_SMTP_PORT 
           value: "587" 
         - name: REDMINE_SMTP_DOMAIN 
           value: "yourdomain.com" 
         - name: REDMINE_SMTP_STARTTLS_AUTO 
           value: "false" 
         - name: REDMINE_SMTP_AUTHENTICATION 
           value: "none" 
 ``` 

 ## 4. **Test Redmine Email Functionality** 

 ### Method 1: Test from Redmine Console 
 ```bash 
 # Access Redmine pod 
 kubectl exec -it redmine-pod -- /bin/bash 

 # Start Rails console 
 bundle exec rails console 

 # Test email sending 
 ActionMailer::Base.mail( 
   from: 'redmine@yourdomain.com', 
   to: 'test@example.com', 
   subject: 'Test from Redmine', 
   body: 'This is a test email from Redmine' 
 ).deliver_now 
 ``` 

 ### Method 2: Use Redmine's Test Function 
 1. Log into Redmine as Admin 
 2. Go to **Administration → Settings → Email notifications** 
 3. Click "Send a test email" 
 4. Enter your email address 

 ## 5. **Customizing Redmine's "From" Address** 

 To ensure Redmine uses your Gmail address properly: 

 ### Option A: Configure in Redmine Settings 
 ```yaml 
 # Update configuration.yml 
 email_delivery: 
   smtp_settings: 
     # ... existing settings ... 
   # Add email_from setting 
 email_from: '"Redmine" <your-email@gmail.com>' 
 ``` 

 ### Option B: Use Postfix Header Rewriting 
 Ensure your Postfix header_checks ConfigMap handles Redmine emails: 

 ```yaml 
 # Update header_checks in postfix ConfigMap 
 header_checks: | 
   # Rewrite ALL From headers to use your Gmail 
   /^From:.*/ REPLACE From: "Redmine System" <your-email@gmail.com> 
  
   # Or be more specific for Redmine emails 
   /^From:.*redmine.*/ REPLACE From: "Redmine" <your-email@gmail.com> 
   /^From:.*@yourdomain.com/ REPLACE From: "Redmine" <your-email@gmail.com> 
  
   # Ensure proper headers 
   /^Reply-To:.*/ REPLACE Reply-To: "Redmine" <your-email@gmail.com> 
   /^Sender:.*/ REPLACE Sender: your-email@gmail.com 
 ``` 

 ## 6. **Complete Example with Bitnami Redmine** 

 If you're using the Bitnami Redmine chart: 

 ```yaml 
 # values.yaml for Bitnami Redmine 
 smtpHost: "postfix" 
 smtpPort: 587 
 smtpUser: "" 
 smtpPassword: "" 
 smtpProtocol: "" 
 smtpTls: false 
 smtpAuth: "" 
 extraEnvVars: 
   - name: REDMINE_EMAIL_FROM 
     value: "your-email@gmail.com" 
 ``` 

 ## 7. **Verify the Flow** 

 The email flow will be: 
 ``` 
 Redmine → Postfix (K8s Service) → Gmail SMTP → Recipient 
            ↑                              ↑ 
        No auth needed               Uses your Gmail auth 
        (internal traffic)           (App Password) 
 ``` 

 ## 8. **Common Issues and Solutions** 

 ### Issue 1: Connection refused 
 ```bash 
 # Check Postfix is running 
 kubectl get pods -l app=postfix 

 # Check logs 
 kubectl logs postfix-pod 

 # Test connectivity from Redmine pod 
 kubectl exec redmine-pod -- telnet postfix 587 
 ``` 

 ### Issue 2: Emails not sending 
 ```bash 
 # Check Postfix mail queue 
 kubectl exec postfix-pod -- postqueue -p 

 # Check Postfix logs 
 kubectl logs postfix-pod | grep -i "sasl\|tls\|relay" 
 ``` 

 ### Issue 3: Gmail rejecting emails 
 ```bash 
 # Check for authentication errors 
 kubectl logs postfix-pod | grep -i "authentication\|535\|550" 
 ``` 

 ## 9. **Monitoring Email Delivery** 

 ```yaml 
 # Add sidecar for mail log monitoring 
 # postfix-deployment-with-sidecar.yaml 
 apiVersion: apps/v1 
 kind: Deployment 
 metadata: 
   name: postfix 
 spec: 
   template: 
     spec: 
       containers: 
       - name: postfix 
         # ... existing postfix container ... 
       - name: mail-log-tailer 
         image: alpine:latest 
         command: ["sh", "-c"] 
         args: 
           - tail -f /var/log/mail.log 
         volumeMounts: 
         - name: mail-logs 
           mountPath: /var/log 
 ``` 

 ## 10. **Quick Test Commands** 

 ```bash 
 # Test email sending from within cluster 
 cat << EOF | kubectl run -it --rm --image=alpine:latest test-email -- sh 
 apk add mailx 
 echo "Test email body" | mail -s "Test Subject" test@example.com \ 
   -r "Redmine <your-email@gmail.com>" \ 
   -S smtp="postfix:587" 
 EOF 
 ``` 

 This setup allows Redmine to send notifications (issue updates, password resets, etc.) through your Postfix relay, which then sends them via Gmail with your Gmail address as the sender. The emails should have better deliverability since they're properly authenticated through Gmail's SMTP servers.

Back