如何在Django中向dinamic email accout发送电子邮件?

时间:2017-03-23 23:09:00

标签: django email django-forms django-templates

我的模板中有一个联系表单,当用户请求有关房屋的信息时,用户可以联系不同的卖家索取信息,所以我不知道怎么可以发送电子邮件给不同的人,因为你知道在系统中存在多个卖家。

这是我的联系表格:

enter image description here

其中“Nombre”是需要信息的用户的名称,“Mail”是需要信息的用户的电子邮件。

众议院的卖家将收到电子邮件。

我无法使用它:

EMAIL_HOST_USER =

EMAIL_HOST_PASSWORD =

因为不仅一个人会收到所有电子邮件

1 个答案:

答案 0 :(得分:0)

您可以使用to并自定义from django.core.mail import EmailMultiAlternatives def view_where_i_send_email(request): # some view content # vars to render into html email template d = Context({'arg_1': arg_1, 'arg_n' : arg_n,}) # get the template to tge email template = "emailtemplate.html" htmly = get_template(template) # render the template and its content html_content = htmly.render(d) subject = "Subject" from_email = "fromthisemail@domain.com" # HERE you add the emails to wich you want to send to = [email1] to.append(email2) to.append(email3) msg = EmailMultiAlternatives(subject, "", from_email, to) msg.attach_alternative(html_content, "text/html") msg.send() 列表

你可以尝试:

CREATE TABLE `points` (
  `id` int(10) unsigned NOT NULL,
  `player_id` int(10) unsigned NOT NULL,
  `game_id` int(10) unsigned NOT NULL,
  `score` int(11) NOT NULL,
  `isScore` tinyint(1) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
);


INSERT INTO `points` (`id`, `player_id`, `game_id`, 
                  `score`, `isScore`,     `created_at`, `updated_at`)
VALUES
(16, 11, 60, 4, 0, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(17, 11, 60, 5, 1, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(18, 12, 60, 6, 0, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(19, 12, 60, 7, 1, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(20, 12, 60, 8, 0, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(21, 12, 60, 9, 1, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(22, 8, 60, 10, 0, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(23, 8, 60, 11, 1, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(24, 12, 60, 12, 1, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(25, 12, 60, 13, 1, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(26, 5, 60, 14, 1, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(27, 12, 60, 15, 0, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(28, 12, 60, 16, 1, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(29, 10, 60, 17, 1, '2016-12-28 12:19:39', '2016-12-28 12:19:39'),
(30, 10, 60, 18, 1, '2016-12-28 12:19:39', '2016-12-28 12:19:39');