我的任务是针对不同的电子邮件/网络邮件客户端优化 HTML 电子邮件。我曾经通过在 Outlook Express 中执行一个技巧来测试 HTML 文件,使其发送原始 HTML,但微软现在似乎已经停止提供 Outlook Express(我认为“Live Mail”应该取代它)。
所以我的问题是,有没有一种简单、快捷的方法来发送 HTML 电子邮件?甚至可能是一个可以完成这项工作的免费软件程序?
http://docs.python.org/library/email-examples.html 您可以对其进行参数化,封装在函数中,从文件中读取内容等(请确保您将“s = smtplib.SMTP('localhost')”中的 localhost 设置为您的 smtp 服务器)
sendmail.exe(仅限 Windows)。
您可以保存 .html 文件并将其作为电子邮件内容通过命令行传输到该程序中。有来自/到/主题/服务器等的命令行选项这将允许您通过编辑 .html 文件并再次运行命令行来快速发送和重新发送电子邮件。无需编程。
编辑:Linux 上有一个类似的同名命令行工具。
甚至去任何语言... 我会停在
MailChimp 并设置一个 免费帐户(最多 500 个订阅者,每月发送 3000 次)... 3000 次发送足以测试,对吗? :) 它拥有专业发送电子邮件所需的所有工具(也许还可以为您的客户/朋友设置一个帐户,以便他们/他可以在新闻通讯中使用 MailChimp)
当您使用它时,请查看他们的
资源页面以及完美的工具,以了解我们可以使用CampaignMonitor自己的电子邮件客户端中的CSS支持指南在新闻通讯中使用什么 希望有帮助
require "mail"
options = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "smtp.gmail.com",
:user_name => "[email protected]",
:password => "password",
:enable_starttls_auto => true,
:authentication => :plain,
}
Mail.defaults do
delivery_method :smtp, options
end
mail = Mail.new do
to "[email protected]"
from "Me Me [email protected]"
subject "test email"
html_part do
content_type "text/html; charset=UTF-8"
body File.read("index.html")
end
end
mail.deliver
不要忘记启用来自https://www.google.com/settings/security/lesssecureapps
在网络浏览器(如网页)中查看
渲染 html,然后ctrl+a
选择整个页面,然后
ctrl+c
复制并ctrl+v
将渲染的html结果粘贴到电子邮件正文中。没有比这更容易的了...请注意,如果您希望收件人看到您的图像,则需要托管它们。
using System.Net;
using System.Net.Mail;
var fromAddress = new MailAddress("[email protected]", "From Name");
var toAddress = new MailAddress("[email protected]", "To Name");
const string fromPassword = "fromPassword";
const string subject = "Subject";
const string body = "Body";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
请参阅通过 Gmail 在 .NET 中发送电子邮件
function sendHtml(recipients, subject, html) {
var mail = Server.CreateObject("CDO.Message");
mail.From = "Tester <[email protected]>";
mail.Subject = subject;
mail.To = recipients.join(";");
mail.HTMLBody = html;
// Do the following if you want to directly use a specific SMTP server
mail.Configuration.Fields.Item(
"http://schemas.microsoft.com/cdo/configuration/sendusing") = 2;
mail.Configuration.Fields.Item(
"http://schemas.microsoft.com/cdo/configuration/smtpserver")
= "smtp.example.com";
mail.Configuration.Fields.Item(
"http://schemas.microsoft.com/cdo/configuration/smtpserverport")
= 25;
mail.Configuration.Fields.Update();
mail.Send();
}
但是,使用此方法您的 HTML 可能会稍微重新格式化。
您可以读取电子邮件模板并分配给 MailMessage 正文。
发送电子邮件
System.Net.Mail.MailMessage msg = CreateMailMessage();
SmtpClient sc = new SmtpClient();
sc.Host = ConfigurationManager.AppSettings["SMTPServer"];
sc.Port = 0x19;
sc.UseDefaultCredentials = true;
sc.Send(msg);