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 8133173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:31:41+00:00 2026-06-06T09:31:41+00:00

I am working on web form which collects certain user information from users and

  • 0

I am working on web form which collects certain user information from users and sends confirmation by email. I am trying to user the following approach to send the HTML email as it make managing HTML based email easy.

https://gist.github.com/1668751

I made necessary changes to the code but it is not working. I read other related article to make it work but i am doing something wrong.

Following line of code generates error The replacements dictionary must contain only strings.

MailMessage msgHtml = mailDef.CreateMailMessage(to, replacements, MessageBody, new System.Web.UI.Control());

I have made many change to the code but it doesnt seem to work for me. I would appreciate help to make this code work.

If i comment the above line of code with some other changes then i can send email but i can’t replace the token. Any easy approach to replace token is also welcome.

Below is the Complete code i am using right now

String to, subject, Name;
subject = "Booking Confirmation";
Name = txtName.text;


ListDictionary replacements = new ListDictionary();
replacements.Add("<%Name%>", Name);
replacements.Add("<%Email%>", objVR.Email);
replacements.Add("<%CompanyName%>", objVR.CompanyName);
replacements.Add("<%BookingDate%>", objVR.BookingDate);
replacements.Add("<%BookingTime%>", objVR.TimeSlot);
replacements.Add("<%NoOfVisitors%>", objVR.NoOfVisitors);
replacements.Add("<%BookingCode%>", objVR.BookingUniqueID);


MailDefinition mailDef = new MailDefinition();

string MessageBody = String.Empty;
string filePath = System.Web.HttpContext.Current.Request.PhysicalApplicationPath;

using (StreamReader sr = new StreamReader(filePath + @"\en\VREmailEnglish.htm"))
{
    MessageBody = sr.ReadToEnd();
}

MailMessage msgHtml = mailDef.CreateMailMessage(to, replacements, MessageBody, new System.Web.UI.Control());

string message = msgHtml.Body.ToString();

Helper.SendTokenEmail(to, subject, msgHtml, isHtml);




public static void SendTokenEmail(string to, string subject, string mailMessage, bool isHtml)
        {
            try
            {
                // Create a new message
                var mail = new MailMessage();

                // Set the to and from addresses.
                mail.From = new MailAddress("noreply@somedomain.net");
                mail.To.Add(new MailAddress(to));

                // Define the message
                mail.Subject = subject;
                mail.IsBodyHtml = isHtml;
                mail.Body = mailMessage.ToString();
                //Object userState = mailMessage;

                // Create a new Smpt Client using Google's servers
                var mailclient = new SmtpClient();
                mailclient.Host = "mail.XYZ.net";
                //mailclient.Port = 587; //ForGmail
                mailclient.Port = 2525;

                mailclient.EnableSsl = false;
                mailclient.UseDefaultCredentials = true;

                // Specify your authentication details

                mailclient.Credentials = new System.Net.NetworkCredential("noreply@somedomain.net", "XYZPassword");

                mailclient.Send(mail);
                mailclient.Dispose();
            }
            catch (Exception ex)
            {
            }

        }
  • 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-06T09:31:44+00:00Added an answer on June 6, 2026 at 9:31 am

    As pointed out by HatSoft the ListDictionary accepts objects as key and value so this looks like it should work.

    But reading the docs for the CreateMailMessage() method here http://msdn.microsoft.com/en-us/library/0002kwb2.aspx indicates you need to convert the value to a string otherwise it will throw an ArgumentException.

    So to fix make sure all values you add to the ListDictionary are converted to string i.e

    objVR.BookingDate.ToString()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a web form which works in a following way. Read email
I am currently working on a form which posts to a web service. The
I'm working on a web form which works fine as long as it posts
I am working on a form in which users are asked to provide a
I have a web form which works fine until you keep on working on
I'm working on a small web form that requires the user to input (among
I am working on a ASP.NET MVC web site which has a form that
I have a web application that is working great while running form VS, but
Hi I have a web form that sends a string to one php file
I am trying to upload images via a form which sits in partial view

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.