Python Forum
How to send notifications to gmail from contact form using Django and pushbullet
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to send notifications to gmail from contact form using Django and pushbullet
#1
I'm helping someone update a website that was built a few years ago using Django. On the site there is a contact form that a user fills out and the request is sent to the site admin. My friend wants to get notifications to their gmail account also when the contact form is submitted. The previous developer wrote a code that seems to attempt to do this with Pushbullet API. I'm not familiar with using Pushbullet so I'm trying to find out how this is supposed to work. If anyone is familiar with this way of sending notifications to gmail via the Pushbullet API please enlighten me a bit. I've included the code that is supposed to accomplish the goal.

  

import logging
import os
from typing import List

from django.core.mail import EmailMessage
from pushbullet import PushBullet

# todo Add mr tires api to .env
pb = PushBullet(os.getenv("PUSHBULLET_API"))

# Get an instance of a logger
logger = logging.getLogger('mail_admins')


class Notify:
    subject: str
    message: str
    from_: str = "[email protected]"
    to: List[str] = [
        '[email protected]'
        '[email protected]',
        # '[email protected]',
    ]
    bcc: List[str] = [
        # '[email protected]',
        '[email protected]'
    ]
    reply_to: List[str] = ['[email protected]']

    @staticmethod
    def send(subject: str, message=''):
        try:
            logger.info(f"Sending email:\nSubject: {subject}\nMessage:{message}...")
            email = EmailMessage(subject, message, Notify.from_, Notify.to, Notify.bcc, reply_to=Notify.reply_to)
            email.send(fail_silently=False)
        except Exception as e:
            logger.error("Failed to send email", e)
        try:
            logger.info("Attempting to send pushbullet message.")
            pb.push_note(subject, message, email="[email protected]")
            pb.push_note(subject, message)
        except Exception as e:
            logger.error("Failed to Pushbullet message", e)
            pass


if __name__ == '__main__':
    # notify = Notify()
    # notify.send("TestSubject", "TestMessage")
    push = pb.push_note("Test", "This is the body", email="[email protected]")
 
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Gmail API - Error 400: redirect_uri_mismatch Depp 1 1,542 Jun-12-2022, 10:42 AM
Last Post: snippsat
  find a hyperlink in Gmail body python 3(imap and selenium) taomihiranga 1 8,117 Dec-30-2020, 05:31 PM
Last Post: Gamer1057
  Not able to sign into gmail using selenium Leo_Red 4 5,695 Nov-19-2020, 05:03 AM
Last Post: Leo_Red
  Auto-Updating Dashboard w/ Notifications Kadin 1 1,496 Sep-28-2020, 12:17 PM
Last Post: DeaD_EyE
  Django send email - email form Remek953 2 2,247 Sep-18-2020, 07:07 AM
Last Post: Remek953
  Django admin form with parent child tmmaersk 0 1,836 Apr-02-2020, 06:42 AM
Last Post: tmmaersk
  Contact form button click action Man_from_India 1 2,752 Feb-01-2020, 06:21 PM
Last Post: snippsat
  Send email to gmail after user fill up contact form and getting django database updat Man_from_India 0 2,071 Jan-22-2020, 03:59 PM
Last Post: Man_from_India
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,246 Jun-30-2019, 12:21 AM
Last Post: scidam
  How to send data from remotely hosted HTML form to Pi sajid 2 2,532 Jun-27-2019, 10:28 PM
Last Post: sajid

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020