Eigener Mailserver als Smarthost (LDAP, Dovecot, Postfix, Getmail)

Debian macht sich hervorragend als Web- und Mailserver. Schau auch in den " Tipps und Tricks"-Bereich.
Antworten
sharbich
Beiträge: 284
Registriert: 27.09.2013 21:12:40

Eigener Mailserver als Smarthost (LDAP, Dovecot, Postfix, Getmail)

Beitrag von sharbich » 30.04.2021 21:08:42

Hallo Ihr Lieben,
ich habe mir einen eigenen Mailserver gegönnt. Mails versende und empfange ich über ein Mail Relay vServer mit fester IP wo auch meine Domäne gehostet wird. Das versenden und empfangen meiner Mailadressen z. B. hans.mustermann@example.de funktioniert.
Benutzerdaten werden im LDAP verwaltet.
Nun möchte ich pro User versus Mailpostfach auch von seinen vorhandenen alten Mailpostfächer (t-online.de, gmx.de, yahoo.de,etc.) die Mails ins vorhandene Postfach runterladen. Dazu verwende ich ein Python Scipt und getmail. Allerdings werden die Mails zwar runtergeladen und ins data Verzeichnis von Getmail gespeichert, aber nicht ins lokale Postfach weitergeleitet. Noch viel schlimmer wieder zurück ins vorhandenen Postfach versendet. Doch der Reihe nach. Hier mein Python Script https://nopaste.debianforum.de/41361
Meine getmail Konfigurationen:

Code: Alles auswählen

secmail@dsme01:~$ cat getmail-ldap.cfg 
[Main]
# Path to getmail
GetmailBinary=/usr/bin/getmail
# Directory that should be used as a storage by getmail
GetmailDir=/home/secmail/getmail_data
# Read default values for getmail from this file
DefaultGetmailConfigFile=/home/secmail/getmailrc_template.cfg
# Save the final configuration files which include the LDAP details to this directory
ConfigFileOutputDir=/home/secmail/getmail_config
 
[Logging]
verbose = 0
# Write messages to the following log file
LogFile=/var/log/getmail-ldap.log
# If a severe error occures a mail goes to the admin
# SMTP-Server to use for sending this error notification
MailServer=dsme01.intern.example.de
# Mail address of the sender of this error notification
MailFrom=secmail@example.de
# Recipients of this error notification
# separate multiple recipients by comma
MailTo=root@example.de
# Subject of the error notification
MailSubject=Getmail-LDAP Error
 
[LDAP]
# Read LDAP information from this server
LDAPServer=ldaps://ldap.intern.example.de
# Authenticate with the following DN
BindDN=uid=secmail, ou=users, dc=example, dc=de
# Authenticate with the following password
BindPassword=#######
# Restrict search of external mail accounts to this DN
SearchDN=ou=users, dc=example, dc=de
# Scope of search for external mail accounts
# Possible values include SUB, ONE and BASE
SearchScope=SUB
# Identify external mail accounts with the following filter
SearchFilter=(&(dcSubMailAddress=*)(objectClass=dcExternalMailAccount)(dcAccountStatus=active)(dcRetrieveType=*)(dcRetrieveLogin=*)(dcRetrievePassword=*))
# List of LDAP-Attributes used to determine the following variables
#       1. Name for resulting getmail configuration file (must be unique)
#	2. Type for mail collection e.g. BrokenUIDLPOP3Retriever
#	3. Mail server to collect mails from
#	4. Login for mail server
#       5. Password for mail server
# separate by comma
RelevantAttributes=dcSubMailAddress,dcRetrieveType,dcRetrieveServer,dcRetrieveLogin,dcRetrievePassword

Code: Alles auswählen

secmail@dsme01:~$ cat getmailrc_template.cfg 
[options]
verbose = 0
# for testing do not delete mails
delete = false
## delete = true
message_log = /var/log/getmail.log
## read_all = true
read_all = false
# do not manipulate the header
delivered_to = false
received = false

[retriever]
type =
server =
username =
password = 
 
[destination]
type = MDA_external
path = /usr/sbin/sendmail
arguments = ("-bm", "stefan.harbich@example.de")
Starte ich als secmail User das Python Script erhalte ich folgende Meldungen

Code: Alles auswählen

secmail@dsme01:~$ ./getmail-ldap.py 
/home/secmail/getmail_config/getmail_sharbich@t-online.de.cfg
Name sharbich@t-online.de
Type SimplePOP3SSLRetriever
Server securepop.t-online.de
Login sharbich@t-online.de
Password ##############
-----------------
DN: dcSubMailAddress=sharbich@t-online.de,uid=stefan.harbich,ou=users,dc=example,dc=de
Name: uid
  Value: stefan.harbich
Name: dcretrievepassword
  Value: ##############
Name: objectclass
  Value: dcExternalMailAccount
  Value: top
  Value: dcPosixSubAccount
Name: dcsubmailaddress
  Value: sharbich@t-online.de
Name: uidnumber
  Value: 10000
Name: dcretrievelogin
  Value: sharbich@t-online.de
Name: dcretrieveserver
  Value: securepop.t-online.de
Name: dcposixownerurl
  Value: ldap:///uid=stefan.harbich,ou=users,dc=example,dc=de?uid,uidNumber,gidNumber,dcMailMessageStore?base?(&(objectClass=posixAccount)(objectClass=dcMailUser))
Name: gidnumber
  Value: 10000
Name: dcaccountstatus
  Value: active
Name: dcmailmessagestore
  Value: /vmail/mailboxes/example.de/stefan.harbich/mail
Name: dcretrievetype
  Value: SimplePOP3SSLRetriever
========
Zeigen die log Dateien folgendes an

Code: Alles auswählen

root@dsme01:~# tail -f /var/log/getmail.log 
2021-04-30 19:07:47 msg 3/6 (6104 bytes) msgid 1192286819.25903 from <openldap-technical-bounces@openldap.org> delivered to MDA_external command sendmail ()

Code: Alles auswählen

root@dsme01:~# tail -f /var/log/getmail-ldap.log
INFO 2021-04-30 19:38:27,419 main_call 314 Writing Account Configuration for sharbich@t-online.de to file /home/secmail/getmail_config/getmail_sharbich@t-online.de.cfg
Irgendetwas scheint im Python Script an folgender Stelle nicht in Ordnung zu sein das getmail die Nachricht an sharbich@t-online.de sendet?

Code: Alles auswählen

. . .
	def set_pop3_account(self, newRetrieveAccount):
		self.set('retriever','server',newRetrieveAccount.server)
		self.set('retriever','type',newRetrieveAccount.account_type)
		self.set('retriever','username',newRetrieveAccount.login)
		self.set('retriever','password',newRetrieveAccount.password)
		self.set('destination','arguments','("'+newRetrieveAccount.account_name+'",)')
	def write(self):
. . .
Habt Ihr noch eine Idee wo ich ansetzen kann?

Gruß von Stefan Harbich

Antworten