Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8308447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:49:07+00:00 2026-06-08T18:49:07+00:00

I am a new ASP.NET developer and I am developing a traning management system

  • 0

I am a new ASP.NET developer and I am developing a traning management system that will send a weekly email notifications to the employees in my department to participate in a weekly short training quiz. Everything works fine. And for sending the email notifications, of course I am using the C# Mail function. The email is a text-based email, and it will be included the link to the new quiz on a weekly basis.

Now, I want to make this text-based email as a an image-based email. There is a speicific part in that image will be as a link to the new quiz. So every week there will be a new link under that part of the image. I am struggling with this part and I don’t know how to modify my C# Mail function to deal with it. This is my first time to send an image using C# Mail function. I searched a lot on Google and I got confused.
FYI, I designed my Mail function to deal with sending the same email to more than 200 users by spliting them into lists of 10 users as shown below.

Could you please help me in modifying the code shown below to deal with sending that image? Let us assume that we have any image.

C# Code:

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


    protected void SendEmail(string toAddresses, string fromAddress, string MailSubject, string MessageBody, bool isBodyHtml)
    {
        SmtpClient sc = new SmtpClient("Mail Server");
        try
        {
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("Test@MailServer.com", "TestSystem");


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

    }

    protected void SendEmailTOAllUser()
    {
        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("@MailServer.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 = @".................................. ";

                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);
                            addressesToSend.Clear();
                            sendCount = 0;
                        }
                    }

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

UPDATE:

Guys, you did not get what I mean. The whole email will be an image, and small part like small circle of that image will be as a hyperlink not the whole image. And that link we will be changed every week such as default.aspx/testid=12 and so on. So how to do that?

UPDATE #2:
I updated the following part of my code to include image but I am facing a problem with adding the AlternateViews.ADD(av). How to fix this?

string body = @"........................";
                            ";
                AlternateView av = AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html);
                LinkedResource lr = new LinkedResource("~/EmailNotification.jpg");
                lr.ContentId="image1";
                av.LinkedResources.Add(lr);
                //msg.AlternateViews.Add(av);

UPDATE #3:

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 Adderess");
        try
        {
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("test@MailServer.com", "TestSystem");


            //QuizLink is appSetting inside your web config
            string newLink = System.Configuration.ConfigurationManager.AppSettings["QuizLink"].ToString();

            string html = "<h1>Quiz!</h1><img src=/fulladdress/someimage.png usemap ='#clickMap'>";
                   html += "<map id =\"clickMap\" name=\"clickMap\">" +
                            "<area shape =\"rect\" coords =\"0,0,82,126\" href ="+ newLink +" alt=\"Quiz\" /></map>";


            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(",");
                            }

                            sbEmailAddresses.Append(sName).Append("@MailServer");
                        }
                    }
                }
                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 = @".............................";
                AlternateView av = AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html);
                LinkedResource lr = new LinkedResource("~/EmailNotification.jpg", MediaTypeNames.Image.Jpeg);
                lr.ContentId="image1";
                av.LinkedResources.Add(lr);
                //msg.AlternateViews.Add(av);


                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();
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:49:08+00:00Added an answer on June 8, 2026 at 6:49 pm

    You have to send Image as part HTML. Use following code

    myemail.Body = "<h1>Quiz!</h1><img src=/fulladdress/someimage.png onclick="location.href='myPage.html'">";
    
    myemail.IsBodyHtml = true; //Send this as plain-text
    

    I have taken help from these links. Hope it would be also Helpfull to you

    1. http://www.intstrings.com/ramivemula/c/how-to-send-an-email-using-c-net-with-complete-features/

    2. Send a email with a HTML file as body (C#)

    UPDATE

    Store your Quiz URL in Database, so that it could be changed every week
    Use image map to create a part of image clickable. Build the html as below.

    //in this case your newLink would be default.aspx/testid=12
    string newLink = GetNewLinkFromDB();
    
    
    string html = "<h1>Quiz!</h1><img src=/fulladdress/someimage.png usemap ="#clickMap">";
    html += "<map id =\"clickMap\" name=\"clickMap\">
    <area shape =\"rect\" coords =\"0,0,82,126\" href ="+ newLink +" alt=\"Quiz\" />
    </map>"
    

    Update 2

    protected void SendEmail(string toAddresses, string fromAddress, string MailSubject, string MessageBody, bool isBodyHtml)
        {
            SmtpClient sc = new SmtpClient("MailServer");
            try
            {
                MailMessage msg = new MailMessage();
                msg.From = new MailAddress("test@mailServer.com", "TestSystem");
    
    
                //QuizLink is appSetting inside your web config
                string newLink = System.Configuration.ConfigurationManager.AppSettings["QuizLink"].ToString();
    
    
        string html = "<h1>Quiz!</h1><img src=/fulladdress/someimage.png usemap ="#clickMap">";
        html += "<map id =\"clickMap\" name=\"clickMap\">
        <area shape =\"rect\" coords =\"0,0,82,126\" href ="+ newLink +" alt=\"Quiz\" />
        </map>"
    
                msg.Bcc.Add(toAddresses);
                msg.Subject = MailSubject;
                msg.Body = html ;
                msg.IsBodyHtml = isBodyHtml;
                sc.Send(msg);
            }
            catch (Exception ex)
            {
                throw ex;
            }
    
        }
    

    **UPDATE **

    string html = "<h1>Quiz!</h1><img src='" + src + "' usemap ='#clickMap'>";
                html += "<map id =\"clickMap\" name=\"clickMap\">" +
                         "<area shape =\"rect\" coords =\"0,0,82,126\" href =" + quickLink + "alt=\"Quiz\" title='Click For Quiz'/></map>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a new ASP.NET developer and I am developing a web-based suggestions box
I'm planning a new ASP.NET project that will become a product that is installed
I created a new ASP.NET website using Visual Web Developer 2008 Express edition and
I'm developer moving from C# to Java. Heard about new ASP net feature. <%:
I am a brand new Java developer (I have been working in asp.net) and
Using ASP.Net Am New to website development Currently am developing a web pages, when
I am a new ASP.NET developer and now I am having an issue in
Background I am developing an ASP.Net server side control that needs to talk to
Long time ASP.NET Webforms developer, new to Ajax development (mostly via the UpdatePanel control
I am developing a application for Sales Order Management using ASP.NET MVC 3.0. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.