显示图像内的电子邮件消息从网站发送使用c# asp.net

本文关键字:net asp 网站 图像 显示图 消息 电子邮件 显示 | 更新日期: 2023-09-27 18:03:51

是否可以在电子邮件中显示一个图像,这是从用户的网站发送的?此映像在本地主机中显示并运行。

如果是,那么怎么办?我已经尝试过一次,但无法显示图像。我从我的应用程序发送以下html模板到我的电子邮件。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Reset your password</title>
</head>
<body>
    <img src="http://localhost:3440/img/blue/logo.png" alt="Odiya doctor" /><br />
    <br />
    <div style="border-top: 3px solid #22BCE5">
        &nbsp;</div>
    <span style="font-family: Arial; font-size: 10pt">Hello <b>User</b>,<br />
        <br />
        For reset your password please click on below link<br />
        <br />
        <a style="color: #22BCE5" href="{Url}">Click me to reset your password</a><br />
        <br />
        <br />
        Thanks<br />
        For contacting us.<br />
        <a href="http://localhost:3440/localhost:3440/index.aspx" style="color: Green;">Odiya
            doctor</a> </span>
</body>
</html>

index.aspx.cs:

protected void userPass_Click(object sender, EventArgs e)
{
  string body= this.GetBody("http://localhost:3440/resetPassword.aspx");
  this.sendEmailToUser(respassemail.Text.Trim(), body);
}
private string GetBody(string url)
        {
            string body = string.Empty;
            using (StreamReader reader= new StreamReader(Server.MapPath("~/emailBodyPart.htm")))
            {
                body = reader.ReadToEnd();
            }
            body = body.Replace("{Url}", url);
            return body;
        }
        private void sendEmailToUser(string recepientEmail, string body)
        {
            using (MailMessage mailMessage = new MailMessage())
            {
                try
                {
                    mailMessage.From = new MailAddress(ConfigurationManager.AppSettings["UserName"]);
                    mailMessage.Subject = "Password Reset";
                    mailMessage.Body = body;
                    mailMessage.IsBodyHtml = true;
                    mailMessage.To.Add(new MailAddress(recepientEmail));
                    SmtpClient smtp = new SmtpClient();
                    smtp.Host = ConfigurationManager.AppSettings["Host"];
                    smtp.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSsl"]);
                    System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
                    NetworkCred.UserName = ConfigurationManager.AppSettings["UserName"];
                    NetworkCred.Password = ConfigurationManager.AppSettings["Password"];
                    smtp.UseDefaultCredentials = true;
                    smtp.Credentials = NetworkCred;
                    smtp.Port = int.Parse(ConfigurationManager.AppSettings["Port"]);
                    smtp.Send(mailMessage);
                    resetText.InnerText = "";
                    resetText.InnerText = "Check your email to reset your password.In case you did not find in inbox of your email please chcek the spam.";
                    resetText.Style.Add("color", "green");
                }
                catch (Exception e)
                {
                    resetText.InnerText = "";
                    resetText.InnerText = "Email sending failed due to :"+e.Message;
                    resetText.Style.Add("color", "red");
                }

            }
        }

当上面的html模板已经发送到电子邮件,在电子邮件消息我无法显示图像。

显示图像内的电子邮件消息从网站发送使用c# asp.net

如果图像是通过localhost托管的,那么只有在个人用户机器的本地主机上打开电子邮件时才能工作。无法在其他机器上解析本地主机。(电脑、手机、平板电脑等)

如果你想让它在其他地方工作,服务器将不得不暴露一个可以解析的URL/IP