GVKun编程网logo

如何发送HTML格式的电子邮件?[重复](怎么发送html邮件)

15

本文将分享如何发送HTML格式的电子邮件?[重复]的详细内容,并且还将对怎么发送html邮件进行详尽解释,此外,我们还将为大家带来关于ASP.NETMVC:如何使用控制器发送HTML电子邮件?、bas

本文将分享如何发送HTML格式的电子邮件?[重复]的详细内容,并且还将对怎么发送html邮件进行详尽解释,此外,我们还将为大家带来关于ASP.NET MVC:如何使用控制器发送HTML电子邮件?、bash – 发送Html页面作为使用“mutt”的电子邮件、bash – 如何设置Airflow的电子邮件配置以发送有关错误的电子邮件?、css – HTML格式的电子邮件不会在Gmail中显示,而是在其他邮件客户端中显示的相关知识,希望对你有所帮助。

本文目录一览:

如何发送HTML格式的电子邮件?[重复](怎么发送html邮件)

如何发送HTML格式的电子邮件?[重复](怎么发送html邮件)

这个问题已经在这里有了答案

使用SmtpClient通过C#发送HTML电子邮件 (6个答案)

5年前关闭。

我可以让Web应用程序使用Windows Task
Scheduler发送自动电子邮件。现在,我想使用我编写的用于发送电子邮件的以下方法发送HTML格式的电子邮件。

我的后台代码:

protected void Page_Load(object sender, EventArgs e)    {        SmtpClient sc = new SmtpClient("mail address");        MailMessage msg = null;        try        {            msg = new MailMessage("xxxx@gmail.com",                "yyyy@gmail.com", "Message from PSSP System",                "This email sent by the PSSP system");             sc.Send(msg);        }        catch (Exception ex)        {            throw ex;        }        finally        {            if (msg != null)            {                msg.Dispose();            }        }    }

怎么做?我只想在电子邮件中放一些带有一个链接的粗体文本,也许还有一张图像。

答案1

小编典典

设置isBodyHtmltrue允许您在消息正文中使用HTML标记:

msg = new MailMessage("xxxx@gmail.com",                "yyyy@gmail.com", "Message from PSSP System",                "This email sent by the PSSP system<br />" +                "<b>this is bold text!</b>");msg.IsBodyHtml = true;

ASP.NET MVC:如何使用控制器发送HTML电子邮件?

ASP.NET MVC:如何使用控制器发送HTML电子邮件?

使用asp.net发送自定义html电子邮件的最简单方法是什么?

我想理想情况下我想通过电子邮件发送html而不是像往常一样通过ActionResult将其返回到浏览器.通过这种方式,我可以将电子邮件构建为视图,通过模型为其提供数据,然后使用标准.NET电子邮件内容将其激活.

这可行/这样做的方法?

谢谢,

解决方法

这个 blog post有一个很好的解决方案,可以将View渲染为字符串,以便您可以通过电子邮件发送它.
/// Static Method to render string - put somewhere of your choosing
public static string RenderPartialToString(string controlName,object viewData)
{
     ViewDataDictionary vd = new ViewDataDictionary(viewData);
     ViewPage vp = new ViewPage { ViewData = vd };
     Control control = vp.LoadControl(controlName);

     vp.Controls.Add(control);

     StringBuilder sb = new StringBuilder();
     using (StringWriter sw = new StringWriter(sb))
     {
         using (HtmlTextWriter tw = new HtmlTextWriter(sw))
         {
             vp.RenderControl(tw);
         }
     }

     return sb.ToString();
}

bash – 发送Html页面作为使用“mutt”的电子邮件

bash – 发送Html页面作为使用“mutt”的电子邮件

我一直在使用mutt从另一个应用程序&
它工作正常我必须发送html文件,目前我必须发送
他们作为附件所以我用
mutt -s "hi" -a attach.html user@domain.com < /dev/null

但是如果我尝试发送html文件作为正文如下

mutt -e content_type=text/html Email address -s "subject" < test.html

然后,而不是html文件,我得到html文件的源文本。

有什么办法可以让消息的正文成为html
而不是纯文本?

当我尝试你的命令,mutt告诉我content_type = text / html是一个未知的命令。所以你必须使用“set”命令来使这个工作:
mutt -e "set content_type=text/html" Email address -s "subject" < test.html

这在我的测试中有效。

bash – 如何设置Airflow的电子邮件配置以发送有关错误的电子邮件?

bash – 如何设置Airflow的电子邮件配置以发送有关错误的电子邮件?

我试图通过传入一个不起作用的 Bash行(thisshouldnotrun)来故意使一个Airflow任务失败并输出错误.气流输出如下:

[2017-06-15 17:44:17,869] {bash_operator.py:94} INFO - /tmp/airflowtmpLFTMX7/run_bashm2MEsS: line 7: thisshouldnotrun: command not found
[2017-06-15 17:44:17,869] {bash_operator.py:97} INFO - Command exited with return code 127
[2017-06-15 17:44:17,869] {models.py:1417} ERROR - Bash command Failed
Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python2.7/site-packages/airflow/models.py",line 1374,in run
    result = task_copy.execute(context=context)
  File "/home/ubuntu/.local/lib/python2.7/site-packages/airflow/operators/bash_operator.py",line 100,in execute
    raise AirflowException("Bash command Failed")
AirflowException: Bash command Failed
[2017-06-15 17:44:17,871] {models.py:1433} INFO - Marking task as UP_FOR_RETRY
[2017-06-15 17:44:17,878] {models.py:1462} ERROR - Bash command Failed
Traceback (most recent call last):
  File "/home/ubuntu/.local/bin/airflow",line 28,in <module>
    args.func(args)
  File "/home/ubuntu/.local/lib/python2.7/site-packages/airflow/bin/cli.py",line 585,in test
    ti.run(ignore_task_deps=True,ignore_ti_state=True,test_mode=True)
  File "/home/ubuntu/.local/lib/python2.7/site-packages/airflow/utils/db.py",line 53,in wrapper
    result = func(*args,**kwargs)
  File "/home/ubuntu/.local/lib/python2.7/site-packages/airflow/models.py",in execute
    raise AirflowException("Bash command Failed")
airflow.exceptions.AirflowException: Bash command Failed

Airflow会发送这类错误的电子邮件吗?如果没有,发送这些错误的电子邮件的最佳方式是什么?

我甚至不确定airflow.cfg是否设置正确…由于最终目标是测试电子邮件警报通知,我想确保正确设置airflow.cfg.这是设置:

[email]
email_backend = airflow.utils.email.send_email_smtp


[smtp]
# If you want airflow to send emails on retries,failure,and you want to use
# the airflow.utils.email.send_email_smtp function,you have to configure an
# smtp server here
smtp_host = emailsmtpserver.region.amazonaws.com 
smtp_starttls = True
smtp_ssl = False
# Uncomment and set the user/pass settings if you want to use SMTP AUTH
# smtp_user = airflow_data_user
# smtp_password = password
smtp_port = 587 
smtp_mail_from = airflow_data_user@domain.com

什么是smtp_starttls?我在文档或在线中找不到任何相关信息.如果我们有查看电子邮件所需的双因素身份验证,那么这对Airflow来说是个问题吗?

这是我的Bash命令:

task1_bash_command = """
export PATH=/home/ubuntu/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
export rundate=`TZ='America/Los_Angeles' date +%F -d "yesterday"`
export AWS_CONfig_FILE="/home/ubuntu/.aws/config"

/home/ubuntu/bin/sNowsql -f //home/ubuntu/sql/script.sql 1> /home/ubuntu/logs/"$rundate"_dev.log 2> /home/ubuntu/logs/"$rundate"_error_dev.log

if [ -e /home/ubuntu/logs/"$rundate"_error_dev.log ]
then
    exit 64
fi

我的任务是:

task1 = BashOperator(
    task_id = 'run_bash',bash_command = task1_bash_command,dag = dag,retries = 2,email_on_failure = True,email = 'username@domain.com')

解决方法

smtp_starttls基本上意味着使用 TLS

如果要使用SSL,请将此设置为False并将smtp_ssl设置为True.您可能需要smtp_user和smtp_password.

Airflow不会处理2步验证.但是,您使用的是AWS,您可能不需要它,因为您的SMTP(SES)凭据与您的AWS凭据不同.

见here.

编辑:
要使气流在发生故障时发送电子邮件,需要在您的任务,email_on_failure和电子邮件上设置几件事.

在这里看到例如:

def throw_error(**context):
    raise ValueError('Intentionally throwing an error to send an email.')



t1 = Pythonoperator(task_id='throw_error_and_email',python_callable=throw_error,provide_context=True,email_on_failure=True,email='your.email@whatever.com',dag=dag)

css – HTML格式的电子邮件不会在Gmail中显示,而是在其他邮件客户端中显示

css – HTML格式的电子邮件不会在Gmail中显示,而是在其他邮件客户端中显示

我目前从PHP的mail()函数发送html格式的电子邮件,并检查他们只是为了确保他们显示为HTML(格式化,我知道,格式化将(从客户端到客户端) 。他们在Apple Mail客户端以及我的iPhone上显示为HTML。但是,Gmail只是拒绝将其显示为HTML。而且我不是说它的格式不正确,它只是简单地不使用HTML出现。

奇怪的部分是从一个标签的img正在加载,但这是关于它…是我是大多使用divs的布局,这是新的Gmail或什么(vs表)?

就CSS和什么不去,查看原始来源显示以下内容:

<html><head><style>body { background-color: #F2F2F2; font-family: Arial; color: #5C5C5C; font-size: 11pt; } a { color: #46AAFF; text-decoration: none; } #container { width: 750px; margin-right: auto; margin-left: auto; } #header { float: right; padding: 3px; height: 30px; } #header a { color: #666666; margin-right: 10px; } #mainBody { padding: 20px; background-color: #FFF; border: 1px solid #DADADA; border-radius: 3px; } #imageArea { border-top: solid #E8E8E8 1px; margin: 15px; } #singleImageArea { width: 250px; padding: 15px; } #singleImageArea p { float: right; line-height: 30px; width: 130px; margin-top: 20px; } #footer { padding: 10px; color: gray; } #footer p { text-shadow: 0px 2px #FFF; font-size: 10pt; } #footer a { color: #ADADAD; float: right; padding-left: 20px; padding-right: 20px; } #footer img { width: 35px; height: 23px; padding: 10px; float: left; } </style></head><body><div id="container"><div id="header"><a href="http://appname.local/login/">Login</a></d
 iv><div></div><div id="mainBody"><h1>Hi Josh Holat!</h1>You've sent a request to <strong>reset</strong> your appname password. Just click the link below <em>(or copy and paste it into your browser)</em> and follow the instructions to set a new password. The link will expire in one hour.<br/><br/><a href="http://appname.local/sb/reset-password/?r=2768af61698fcde9c04f9449351575d6bfe6d720">http://appname.local/sb/reset-password/?r=2768af61698fcde9c04f9449351575d6bfe6d720</a><br/><br/>If you feel this request was submitted in error,don't worry; you can safely ignore this e-mail and your password will not be changed.<br/><br/>Much love,<br/>Us</div><!-- #mainBody --><div id="footer"><img src="http://appname.local/images/email/footer_sb.png" /><p>&copy; 2011 appname,Inc. All Rights Reserved <a href="http://appname.local/sb/legal/">Legal</a><a href="http://appname.local/sb/contact/">Contact</a><a href="http://s
 tagebloc.local/sb/developers/">Developers</a><a href="http://appname.local/sb/blog/">Blog</a></p></div><!-- #footer --></div><!-- #container --></body></html>

以及:

Delivered-To: appname@gmail.com
Received: by 10.229.40.2 with SMTP id i2cs133298qce;
        Sun,28 Aug 2011 14:29:08 -0700 (PDT)
Received: by 10.42.152.199 with SMTP id j7mr4419937icw.417.1314566947950;
        Sun,28 Aug 2011 14:29:07 -0700 (PDT)
Return-Path: <_www@joshholat.local>
Received: from joshholat.local (arh2281.urh.uiuc.edu [130.126.70.193])
        by mx.google.com with ESMTP id w3si6800550icz.109.2011.08.28.14.29.06;
        Sun,28 Aug 2011 14:29:06 -0700 (PDT)
Received-SPF: neutral (google.com: 130.126.70.193 is neither permitted nor denied by best guess record for domain of _www@joshholat.local) client-ip=130.126.70.193;
Authentication-Results: mx.google.com; spf=neutral (google.com: 130.126.70.193 is neither permitted nor denied by best guess record for domain of _www@joshholat.local) smtp.mail=_www@joshholat.local
Received: by joshholat.local (Postfix,from userid 70)
    id 775063662E01; Sun,28 Aug 2011 16:29:06 -0500 (CDT)
To: Josh Holat <appname@gmail.com>
Subject: Password Reset Request
X-PHP-Originating-Script: 501:Email.PHP
From: appname <noreply@appname.com>
Content-type: text/html
Message-Id: <20110828212906.775063662E01@joshholat.local>
Date: Sun,28 Aug 2011 16:29:06 -0500 (CDT)

我很困惑为什么第三方客户会显示它很好,但Gmail只是忽略它?

解决方法

Gmail不支持< style>标签。您需要使用内联css使gmail正常工作。

这是一个参考列表。
http://www.campaignmonitor.com/css/

关于如何发送HTML格式的电子邮件?[重复]怎么发送html邮件的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于ASP.NET MVC:如何使用控制器发送HTML电子邮件?、bash – 发送Html页面作为使用“mutt”的电子邮件、bash – 如何设置Airflow的电子邮件配置以发送有关错误的电子邮件?、css – HTML格式的电子邮件不会在Gmail中显示,而是在其他邮件客户端中显示等相关内容,可以在本站寻找。

本文标签: