用django发送动态邮件

时间:2019-07-03 10:20:17

标签: django python-3.x

我正在尝试使用html table内的表单字段发送邮件。邮件功能正常工作,但如何包含表格:

views.py:

from django.shortcuts import render
from main_site.models import artist
from django.urls import reverse_lazy
from .forms import BookartistForm
from django.core.mail import send_mail



def artist_booking(request):
if request.method == "POST":
    form = BookartistForm(request.POST)
    if form.is_valid():
        name = form.cleaned_data['name']
        email = form.cleaned_data['email']
        number = form.cleaned_data['number']
        artist_name = form.cleaned_data['artist_name']
        artist_category = form.cleaned_data['artist_category']
        #event_type = form.cleaned_data['event_type']
        date = form.cleaned_data['date']
        budget = form.cleaned_data['budget']
        location = form.cleaned_data['location']
        description = form.cleaned_data['description']
        print(name,email,number,artist_name,artist_category,date,budget,location,description)
        send_mail('Celebbizz Enquiry',
            '<html>
            <table>
            <tr>
            <th>Contact</th>
            <th>Details</th>

            </tr>
            <tr>
            <td>name</td>
            <td>email</td> 
            </tr>
            </table>
            </html>'
            ,
'admin@celebizz.com',
['nedinemo@daily-email.com'],
fail_silently=False
)
form = BookartistForm

return render(request,'main_site/book_artist.html', {'form': form})

我正在尝试发送包含所有这些字段的邮件。我试图在邮件字段中添加html表不起作用

1 个答案:

答案 0 :(得分:0)

要发送内部带有HTML的动态电子邮件,可以从EmailMultiAlternatives使用:

from django.core.mail import EmailMultiAlternatives