hari ini insyaallah saya akan sedikit menceritakan langkah untuk bisa mengirim email lewan cli ubuntu (dalam kasus ini saya akan menggunakan gmail) yang nanti nya juga bisa di manfaatkan sebagai notifikasi server , berikut langkahnya :
install postfix , mailutils dan yang lain nya
[email protected]:/home/bit# apt-get install mailutils libsasl2-2 ca-certificates libsasl2-modules postfix
edit /etc/postfix/main.cf dengan cara
[email protected]:/home/bit# pico /etc/postfix/main.cf
ubah isi main.cf menjadi
# See /usr/share/postfix/main.cf.dist for a commented, more complete version # Debian specific: Specifying a file name will cause the first # line of that file to be used as the name. The Debian default # is /etc/mailname. #myorigin = /etc/mailname smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu) biff = no # appending .domain is the MUA's job. append_dot_mydomain = no # Uncomment the next line to generate "delayed mail" warnings #delay_warning_time = 4h readme_directory = no # TLS parameters smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key smtpd_use_tls=yes smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache # See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for # information on enabling SSL in the smtp client. #smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination myhostname = localhost #alias_maps = hash:/etc/aliases #alias_database = hash:/etc/aliases virtual_alias_maps = hash:/etc/postfix/virtual recipient_canonical_maps = hash:/etc/postfix/recipient_canonical mydestination = bit-X200CA, localhost.localdomain, , localhost # sesuaikan dengan pc/server anda relayhost = smtp.gmail.com:587 mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all #inet_protocols = ipv4 #myorigin = /etc/mailname smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous smtp_tls_CAfile = /etc/postfix/cacert.pem smtp_use_tls = yes
kemudian file sasl_passwd
[email protected]:/home/bit# pico /etc/postfix/sasl_passwd
isi seperti berikut , sesuaikan passwd nya
generate sasl_passwd dengan perintah yang nntinya akan membentuk file sasl_passwd.db
postmap /etc/postfix/sasl_passwd
selanjutnya kita akan melakukan generate certificate karena kebanyakan email menggunakan koneksi TLS
[email protected]:/etc/ssl/certs# cat /etc/ssl/certs/thawte_Primary_Root_CA_-_G3.pem | tee -a /etc/postfix/cacert.pem
hasil certificate TLS yang di generate kurang lebih seperti berikut
[email protected]:/etc/ssl/certs# cat /etc/ssl/certs/thawte_Primary_Root_CA_-_G3.pem | tee -a /etc/postfix/cacert.pem -----BEGIN CERTIFICATE----- MIIEKjCCAxKgAwIBAgIQYAGXt0an6rS0mtZLL/eQ+zANBgkqhkiG9w0BAQsFADCB rjELMAkGA1UEBhMCVVMxFTATBgNVBAoTDHRoYXd0ZSwgSW5jLjEoMCYGA1UECxMf Q2VydGlmaWNhdGlvbiBTZXJ2aWNlcyBEaXZpc2lvbjE4MDYGA1UECxMvKGMpIDIw MDggdGhhd3RlLCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNlIG9ubHkxJDAiBgNV BAMTG3RoYXd0ZSBQcmltYXJ5IFJvb3QgQ0EgLSBHMzAeFw0wODA0MDIwMDAwMDBa Fw0zNzEyMDEyMzU5NTlaMIGuMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMdGhhd3Rl LCBJbmMuMSgwJgYDVQQLEx9DZXJ0aWZpY2F0aW9uIFNlcnZpY2VzIERpdmlzaW9u MTgwNgYDVQQLEy8oYykgMjAwOCB0aGF3dGUsIEluYy4gLSBGb3IgYXV0aG9yaXpl ZCB1c2Ugb25seTEkMCIGA1UEAxMbdGhhd3RlIFByaW1hcnkgUm9vdCBDQSAtIEcz MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsr8nLPvb2FvdeHsbnndm gcs+vHyu86YnmjSjaDFxODNi5PNxZnmxqWWjpYvVj2AtP0LMqmsywCPLLEHd5N/8 YZzic7IilRFDGF/Eth9XbAoFWCLINkw6fKXRz4aviKdEAhN0cXMKQlkC+BsUa0Lf b1+6a4KinVvnSr0eAXLbS3ToO39/fR8EtCab4LRarEc9VbjXsCZSKAExQGbY2SS9 9irY7CFJXJv2eul/VTV+lmuNk5Mny5K76qxAwJ/C+IDPXfRa3M50hqY+bAtTyr2S zhkGcuYMXDhpxwTWvGzOW/b3aJzcJRVIiKHpqfiYnODz1TEoYRFsZ5aNOZnLwkUk OQIDAQABo0IwQDAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjAdBgNV HQ4EFgQUrWyqlGCc7eT/+j4KdCtjA/e2Wb8wDQYJKoZIhvcNAQELBQADggEBABpA 2JVlrAmSicY59BDlqQ5mU1143vokkbvnRFHfxhY0Cu9qRFHqKweKA3rD6z8KLFIW oCtDuSWQP3CpMyVtRRooOyfPqsMpQhvfO0zAMzRbQYi/aytlryjvsvXDqmbOe1bu t8jLZ8HJnBoYuMTDSQPxYA5QzUbF83d597YV4Djbxy8ooAw/dyZ02SUS2jHaGh7c KUGRIjxpp7sC8rZcJwOJ9Abqm+RyguOhCcHpABnTPtRwa7pxpqpYrvS76Wy274fM m7v/OeZWYdMKp8RcTGB7BXcmer/YB1IsYvdwY9k5vG8cwnncdimvzsUsZAReiDZu MdRAGmI0Nj81Aa6sY6A= -----END CERTIFICATE-----
terakhir reload postfix
[email protected]:/etc/ssl/certs# /etc/init.d/postfix reload
kemudian test kirim email
[email protected]:/etc/ssl/certs# echo "test mail dari local" | mail -s "test postfix" [email protected]
berikut log mail nya
[email protected]:/etc/ssl/certs# tail -f /var/log/mail.log Jun 25 11:17:19 localhost postfix/qmgr[7368]: D526D1A0D5A: removed Jun 25 11:18:28 localhost postfix[7415]: Postfix is running with backwards-compatible default settings Jun 25 11:18:28 localhost postfix[7415]: See http://www.postfix.org/COMPATIBILITY_README.html for details Jun 25 11:18:28 localhost postfix[7415]: To disable backwards compatibility use "postconf compatibility_level=2" and "postfix reload" Jun 25 11:18:28 localhost postfix/master[6678]: reload -- version 3.1.0, configuration /etc/postfix Jun 25 11:18:31 localhost postfix/pickup[7429]: B407F1A0D5A: uid=0 from=<root> Jun 25 11:18:31 localhost postfix/cleanup[7448]: B407F1A0D5A: message-id=<[email protected]> Jun 25 11:18:31 localhost postfix/qmgr[7430]: B407F1A0D5A: from=<[email protected]>, size=338, nrcpt=1 (queue active) Jun 25 11:18:34 localhost postfix/smtp[7450]: B407F1A0D5A: to=<[email protected]>, relay=smtp.gmail.com[74.125.200.108]:587, delay=2.8, delays=0.14/0.19/1.6/0.94, dsn=2.0.0, status=sent (250 2.0.0 OK 1466828314 h189sm3052511pfc.52 - gsmtp) Jun 25 11:18:34 localhost postfix/qmgr[7430]: B407F1A0D5A: removed ^C
kurang lebih email nya seperti ini
selamat mencoba , dan semoga ada yang menyempurnakan 🙂 , termaksih
No Comments, Be The First!