Sending Email Notifications on Seahub

Types of Email Sending in Seafile

There are currently five types of emails sent in Seafile:

  • User reset his/her password
  • System admin add new member
  • System admin reset user password
  • User send file/folder share link and upload link
  • [pro] Reminder of unread notifications (It is sent by a background task which is pro edition only)

The first four types of email are sent immediately. The last type is sent by a background task running periodically.

Options of Email Sending

Please add the following lines to seahub_settings.py to enable email sending.

  1. EMAIL_USE_TLS = False
  2. EMAIL_HOST = 'smtp.example.com' # smpt server
  3. EMAIL_HOST_USER = 'username@example.com' # username and domain
  4. EMAIL_HOST_PASSWORD = 'password' # password
  5. EMAIL_PORT = 25
  6. DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
  7. SERVER_EMAIL = EMAIL_HOST_USER

If you are using Gmail as email server, use following lines:

  1. EMAIL_USE_TLS = True
  2. EMAIL_HOST = 'smtp.gmail.com'
  3. EMAIL_HOST_USER = 'username@gmail.com'
  4. EMAIL_HOST_PASSWORD = 'password'
  5. EMAIL_PORT = 587
  6. DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
  7. SERVER_EMAIL = EMAIL_HOST_USER

Note: If your email service still does not work, you can checkout the log file logs/seahub.log to see what may cause the problem. For a complete email notification list, please refer to email notification list.

Note2: If you want to use the email service without authentication leaf EMAIL_HOST_USER and EMAIL_HOST_PASSWORD blank (''). (But notice that the emails then will be sent without a From: address.)

Note3: About using SSL connection (using port 465)

Port 587 is being used to establish a TLS connection and port 465 is being used to establish an SSL connection. Starting from Django 1.8, it supports both. Until version 5.1 Seafile only supported Django 1.5, which only supports TLS connections. If your email server only supports SSL connections and you are using a Seafile Server version below 5.1, you can find a workaround here: django-smtp-ssl.

Change the sender and reply to of email

You can change the sender and reply to field of email by add the following settings to seahub_settings.py. This only affects email sending for file share link.

  1. # Replace default from email with user's email or not, defaults to ``False``
  2. REPLACE_FROM_EMAIL = True
  3. # Set reply-to header to user's email or not, defaults to ``False``. For details,
  4. # please refer to http://www.w3.org/Protocols/rfc822/
  5. ADD_REPLY_TO_HEADER = True

Config background email sending task (Pro Edition Only)

The background task will run periodically to check whether an user have new unread notifications. If there are any, it will send a reminder email to that user. The background email sending task is controlled by seafevents.conf.

  1. [SEAHUB EMAIL]
  2. ## must be "true" to enable user email notifications when there are new unread notifications
  3. enabled = true
  4. ## interval of sending seahub email. Can be s(seconds), m(minutes), h(hours), d(days)
  5. interval = 30m

Customize email messages

The simplest way to customize the email message is setting the SITE_NAME variable in seahub_settings.py. If it is not enough for your case, you can customize the email templates.

Note: Subject line may vary between different releases, this is based on Release 5.0.0. Restart Seahub so that your changes take effect.

The email base template

seahub/seahub/templates/email_base.html

Note: You can copy email_base.html to seahub-data/custom/templates/email_base.html and modify the new one. In this way, the customization will be maintained after upgrade.

User reset his/her password

Subject

seahub/seahub/auth/forms.py line:127

  1. send_html_email(_("Reset Password on %s") % site_name,
  2. email_template_name, c, None, [user.username])

Body

seahub/seahub/templates/registration/password_reset_email.html

Note: You can copy password_reset_email.html to seahub-data/custom/templates/registration/password_reset_email.html and modify the new one. In this way, the customization will be maintained after upgrade.

System admin add new member

Subject

seahub/seahub/views/sysadmin.py line:424

  1. send_html_email(_(u'Password has been reset on %s') % SITE_NAME,
  2. 'sysadmin/user_reset_email.html', c, None, [email])

Body

seahub/seahub/templates/sysadmin/user_add_email.html

Note: You can copy user_add_email.html to seahub-data/custom/templates/sysadmin/user_add_email.html and modify the new one. In this way, the customization will be maintained after upgrade.

System admin reset user password

Subject

seahub/seahub/views/sysadmin.py line:1224

  1. send_html_email(_(u'Password has been reset on %s') % SITE_NAME,
  2. 'sysadmin/user_reset_email.html', c, None, [email])

Body

seahub/seahub/templates/sysadmin/user_reset_email.html

Note: You can copy user_reset_email.html to seahub-data/custom/templates/sysadmin/user_reset_email.html and modify the new one. In this way, the customization will be maintained after upgrade.

Subject

seahub/seahub/share/views.py line:913

  1. try:
  2. if file_shared_type == 'f':
  3. c['file_shared_type'] = _(u"file")
  4. send_html_email(_(u'A file is shared to you on %s') % SITE_NAME,
  5. 'shared_link_email.html',
  6. c, from_email, [to_email],
  7. reply_to=reply_to
  8. )
  9. else:
  10. c['file_shared_type'] = _(u"directory")
  11. send_html_email(_(u'A directory is shared to you on %s') % SITE_NAME,
  12. 'shared_link_email.html',
  13. c, from_email, [to_email],
  14. reply_to=reply_to)

Body

seahub/seahub/templates/shared_link_email.html

seahub/seahub/templates/shared_upload_link_email.html

Note: You can copy shared_link_email.html to seahub-data/custom/templates/shared_link_email.html and modify the new one. In this way, the customization will be maintained after upgrade.

Reminder of unread notifications

Subject

  1. send_html_email(_('New notice on %s') % settings.SITE_NAME,
  2. 'notifications/notice_email.html', c,
  3. None, [to_user])

Body

seahub/seahub/notifications/templates/notifications/notice_email.html