ASP.NET
.NET Framework 中一套用于生成 Web 应用程序和 XML Web 服务的技术。
20 个问题
如何在电子邮件顶部添加徽标?
我需要一个简单的方法来做到这一点。谢谢
这是我向用户发送电子邮件的代码;我想把标志放在代码string body ="Hello" + txtname.Text.Trim() +",";
前面。
using (MailMessage mm = new MailMessage("support@mywebsite.com", mailtxtbx.Text))
{
mm.Subject = "Activate Account";
string body = "Hello " + txtname.Text.Trim() + ",";
body += "<br /><br />Successful Registration";
body += "<br /><br />Please click the button to activate your account";
body += "<br /><br /><a style='display: block; width: 200px; height: 30px; background: #32CD32;padding: 15px;font-family: Nunito; text-align:center; border-radius: 5px;color: white;font-weight: 700;text-decoration: none;' href = '"
+ Request.Url.AbsoluteUri.Replace("signup.aspx", "activation.aspx?ActCode=" + actCode) + "'>Activate your new account</a>";
body += "<br /><br />Thanks";
mm.Body = body;
mm.IsBodyHtml = true;
SmtpClient SMTP = new SmtpClient("relay-hosting.secureserver.net", 25);
SMTP.UseDefaultCredentials = false;
SMTP.Credentials = new NetworkCredential()
{
UserName = "support@mywebsite.com",
Password = "xxxxxxxxxx"
};
SMTP.EnableSsl = false;
SMTP.Send(mm);
}
Note: 该问题整理于:Adding logo image to email message.
你好,
我建议你可以使用LinkedResource。你可以这样做:
private AlternateView Mail_Body()
{
string path = Server.MapPath(@"Images/photo.jpg");
LinkedResource Img = new LinkedResource(path, MediaTypeNames.Image.Jpeg);
Img.ContentId = "MyImage";
string str = @"
<table>
<tr>
<td>
<img src=cid:MyImage id='img' alt='' width='100px' height='100px'/>
</td>
</tr>
<tr>
<td>
'hello'
</td>
</tr>
</table>
";
AlternateView AV =
AlternateView.CreateAlternateViewFromString(str, null, MediaTypeNames.Text.Html);
AV.LinkedResources.Add(Img);
return AV;
}
using (MailMessage mm = new MailMessage("support@mywebsite.com", mailtxtbx.Text))
{
mm.Subject = "Activate Account";
mm.AlternateViews.Add(Mail_Body());
mm.IsBodyHtml = true;
SmtpClient SMTP = new SmtpClient("relay-hosting.secureserver.net", 25);
SMTP.UseDefaultCredentials = false;
SMTP.Credentials = new NetworkCredential()
{
UserName = "support@mywebsite.com",
Password = "xxxxxxxxxx"
};
SMTP.EnableSsl = false;
SMTP.Send(mm);
}
如果答案是正确的解决方案,请单击“接受答案”并请投赞成票。如果您对此答案有其他疑问,请点击“评论”。
注意:如果您想接收此线程的相关电子邮件通知,请按照我们文档中的步骤启用电子邮件通知。
最好的问候