首页 文章

通过Mailgun和Python发送带有表单数据的电子邮件

提问于
浏览
0

我理解使用Python通过Mailgun API发送消息的基本知识以及来自我网站的请求,并且一切正常 . 我想使用request.forms.get('')附加HTML表单中的数据,但无法找出使其工作的语法 . 下面的链接正是我需要做的,除了Python而不是PHP .

http://www.formget.com/mailgun-send-email/

如何通过Mailgun发送以下表单数据?

HTML FORM (Parts of it to get the point across)

<form action="/send" method="post">
<input name="name" placeholder="Name">
...
<button> ...

ROUTE (Parts of it to get the point across)

@route('/send', method='POST')
def send_simple_message():
variable_I_need_to_send = request.forms.get('firstname')
...
data={...",
        "to": "MyName <myname@gmail.com>",
        "subject": "Website Info Request",
        "text": "Testing some Mailgun awesomness!",
        "html": **variable_I_need_to_send**})
    return '''

谢谢

2 回答

  • 0

    您可以使用requests库:

    import requests
    
    @route('/send/<firstname>', method='POST')
    def send_simple_message(first_name):
        ...
        data={...",
                "from": "{} <address>".format(first_name),
                "to": "MyName <myname@gmail.com>",
                "subject": "Website Info Request",
                "text": "Testing some Mailgun awesomness!",
                "html": '**I need to include form data here**'})
    
        requests.post('http://api_url/', data=data)
        return
    
  • 0

    这对我有用,但不确定这是否是正确的方法:

    @route('/send', method='POST')
    def send_simple_message():
        subject = request.forms.get('name')
        item1 =  request.forms.get('emailaddress')
        item2 =  request.forms.get('phone')
        item3 =  request.forms.get('url')
        item4 =  request.forms.get('about')
        text = item1 + " " + item2 + " " + item3 + " " + item4
        ...
            "to": "Vic <myemail@gmail.com>",
            "subject": subject,
            "html": text})
        return '''
    

相关问题