コード例 #1
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")
コード例 #2
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"})
コード例 #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
ファイル: main.py プロジェクト: capuche777/phish_app
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
コード例 #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 test_send_msg(mail_config):
    msg = MessageSchema(subject="testing",
                        recipients=["*****@*****.**"],

                        body="html test")

    sender = f"{mail_config['MAIL_FROM_NAME']} <{mail_config['MAIL_FROM']}>"
    conf = ConnectionConfig(**mail_config)
    fm = FastMail(conf)
    fm.config.SUPPRESS_SEND = 1
    with fm.record_messages() as outbox:
        await fm.send_message(message=msg, template_name="test.html")

        assert len(outbox) == 1
        assert outbox[0]["subject"] == "testing"
        assert outbox[0]["from"] == sender
        assert outbox[0]["To"] == "*****@*****.**"
コード例 #7
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"})
コード例 #8
0
def send_email(destination, subject, body):
    if settings.admin_email is not None and settings.admin_email_password:
        mail = FastMail(email=settings.admin_email,
                        password=settings.admin_email_password,
                        tls=True,
                        port="587",
                        service="gmail")
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)
        loop.run_until_complete(
            mail.send_message(recipient=destination,
                              subject=subject,
                              body=body,
                              text_format="plain"))
    else:
        print('Email not configured, tried sending:')
        print(f'Header: {subject}')
        print(f'Body: {body}')
コード例 #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 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)
コード例 #11
0
ファイル: send.py プロジェクト: Ju99ernaut/app-listing-server
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")
コード例 #12
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"})
コード例 #13
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")
コード例 #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 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"})
コード例 #16
0
ファイル: auth.py プロジェクト: jmehdipour/kako-server
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)
コード例 #17
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)
コード例 #18
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"})
コード例 #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: 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"})
コード例 #21
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)
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"}
コード例 #23
0
ファイル: email.py プロジェクト: ExpectoAprobarum/BackendSV
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"})
コード例 #24
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)
コード例 #25
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)
コード例 #26
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})
コード例 #27
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)
コード例 #28
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"
コード例 #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}")