0

我正在努力在将使用 C# Mail 功能发送的 HTML 邮件中获取此嵌入图像的地图。一切正常,系统发送电子邮件,图像显示在该电子邮件中,但没有任何映射。你能帮我解决这个问题吗?

注意:图像上的映射区域应该是固定的,它不应该受到调整窗口大小等的影响。

C# 邮件功能:

protected void Page_Load(object sender, EventArgs e)
    {
        Send();
    }


    protected void SendEmail(string toAddresses, string fromAddress, string MailSubject, string MessageBody, bool isBodyHtml, AlternateView av)
    {
        SmtpClient sc = new SmtpClient("Mail Address");
        try
        {
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("test@mailAddress.com", "Test Sys.");


            msg.Bcc.Add(toAddresses);
            msg.Subject = MailSubject;
            msg.Body = MessageBody;
            msg.IsBodyHtml = isBodyHtml;
            msg.AlternateViews.Add(av);
            sc.Send(msg);
        }
        catch (Exception ex)
        {
            throw ex;
        }

    }

    protected void Send()
    {
        string connString = "Data Source=localhost;Initial Catalog=TestDB;Integrated Security=True";

        using (SqlConnection conn = new SqlConnection(connString))
        {
            var sbEmailAddresses = new System.Text.StringBuilder(2000);
            string quizid = "";

            // Open DB connection.
            conn.Open();

            string cmdText = "SELECT MIN (QuizID) As mQuizID FROM dbo.QUIZ WHERE IsSent <> 1";
            using (SqlCommand cmd = new SqlCommand(cmdText, conn))
            {
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        // There is only 1 column, so just retrieve it using the ordinal position
                        quizid = reader["mQuizID"].ToString();

                    }
                }
                reader.Close();
            }

            string cmdText2 = "SELECT Username FROM dbo.employee";
            using (SqlCommand cmd = new SqlCommand(cmdText2, conn))
            {
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        var sName = reader.GetString(0);
                        if (!string.IsNullOrEmpty(sName))
                        {
                            if (sbEmailAddresses.Length != 0)
                            {
                                sbEmailAddresses.Append(",");
                            }
                            // Just use the ordinal position for the user name since there is only 1 column
                            sbEmailAddresses.Append(sName).Append("@mailAddress.com");
                        }
                    }
                }
                reader.Close();
            }

            string cmdText3 = "UPDATE dbo.Quiz SET IsSent = 1 WHERE QuizId = @QuizID";
            using (SqlCommand cmd = new SqlCommand(cmdText3, conn))
            {
                // Add the parameter to the command
                var oParameter = cmd.Parameters.Add("@QuizID", SqlDbType.Int);

                var sEMailAddresses = sbEmailAddresses.ToString();
                string link = "<a href='http://localhost/test.aspx?testid=" + quizid + "'> Click here to participate </a>";
                string body = @"............................";


                body += "<map id =\"clickMap\" name=\"clickMap\"> " +
                     "<area shape =\"rect\" coords =\"752,394,1394,491\" href =" + link + " alt=\"Quiz\" /></map>";


                AlternateView av = AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html);
                LinkedResource lr = new LinkedResource(@"WelcomeMessage.png", MediaTypeNames.Image.Jpeg);
                lr.ContentId="image1";
                av.LinkedResources.Add(lr);


                int sendCount = 0;
                List<string> addressList = new List<string>(sEMailAddresses.Split(','));
                StringBuilder addressesToSend = new StringBuilder();

                if (!string.IsNullOrEmpty(quizid))
                {
                    for (int userIndex = 0; userIndex < addressList.Count; userIndex++)
                    {
                        sendCount++;
                        if (addressesToSend.Length > 0)
                            addressesToSend.Append(",");

                        addressesToSend.Append(addressList[userIndex]);
                        if (sendCount == 10 || userIndex == addressList.Count - 1)
                        {
                            SendEmail(addressesToSend.ToString(), "", "Notification", body, true, av);
                            addressesToSend.Clear();
                            sendCount = 0;
                        }
                    }

                    // Update the parameter for the current quiz
                    oParameter.Value = quizid;
                    // And execute the command
                    cmd.ExecuteNonQuery();
                }

            }
            conn.Close();
        }
    }

*更新: *

最后,我可以让用户点击该部分。我现在想要的是使其固定位置,而不管窗口的大小。这意味着如果用户在小窗口或大窗口中打开电子邮件,则不会影响点击位置。怎么做?

4

1 回答 1

0

尝试这个:

LinkedResource(Server.MapPath(".")  + (@"\images\WelcomeMessage.png", MediaTypeNames.Image.Jpeg);
于 2012-07-29T07:18:55.960 回答