Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi,
I have got a job to do from my employer. It is a very funny one. I have to send an e-mail containing an user input form. When the user clicks the submit button another mail must be sent back to the sender with the information. I have done it properly with Gmail (every thing works fine). But with Yahoo it goes in spam which i bypassed but when the user clicks the submit button it redirects to some other page. The logic was to send an email with isBodyHTML true using HTML form tags action was get and url was the servers url where i created the file for proceesing the data inpuuted by user and send the mail.I have used the gmail smtp for testing
the code is given below:

First Email Sending Code
C#
public string mailbody()
    {
        string strbody="";
        strbody+="<html>";
        strbody+="<body>";
        strbody += "<form id = form1 method=get action=\"url here\">";
   
        strbody += "Name: <input type=text name=\"a\" /><br />";
        strbody+="Age: <input type=text name=\"b\" /><br />";
        strbody += "Location: <input type=text name=\"c\" /><br />";
        strbody+="<input type=submit value=submit id=btnSend/><input type=reset />";
        
        strbody+="</form>";
        strbody += "</html>";
        strbody += "</body>";
        return strbody;

    }
    protected void btnSendMail_Click(object sender, EventArgs e)
    {
       
        try
        {
            string body;
            body = mailbody();
            MailMessage msg = new MailMessage();
            msg.To.Add(new MailAddress(txtEmail.Text)); //To Email address
            msg.From = new MailAddress("siddhesh.patankar5189@gmail.com"); //from email address
            msg.Body = body;
            msg.IsBodyHtml = true;
            SmtpClient smp = new SmtpClient();
            smp.Host = "smtp.gmail.com";
            smp.Port = 587;
            smp.UseDefaultCredentials = true;
            smp.Credentials = new System.Net.NetworkCredential("", ""); //userid, password
            smp.EnableSsl = true;
            smp.Send(msg);
            status.InnerText = "Mail Sent";
            //Response.Write("Mail Sent");
        }
        catch (Exception ex)
        {

            status.InnerText = "Mail Not sent";
            //Response.Write(ex.Message);
        }

    }

Processing the data given by receiver and sending the email back

public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
    {
      string name;
      string age,location;
      string body;
      name=Request.QueryString["a"];  
      age=Request.QueryString["b"];
      location=Request.QueryString["c"];
      body=mailbody(name,age,location);
      
      ///Response.Write(name + "<br />");
      ///Response.Write(age + "<br />");
      ///Response.Write(location + "<br />");
      try
      {
          
          MailMessage msg = new MailMessage();
          msg.To.Add(new MailAddress("feedbackform123@gmail.com"));   //mail to
          msg.From = new MailAddress("feedbackform123@gmail.com"); //mail from
          msg.Body = body;
          msg.IsBodyHtml = true;
          SmtpClient smp = new SmtpClient();
          smp.Host = "smtp.gmail.com";
          smp.Port = 587;
          smp.UseDefaultCredentials = true;
          smp.Credentials = new System.Net.NetworkCredential("", ""); //userid passwd
          smp.EnableSsl = true;
          smp.Send(msg);
          string sScript = "";
          sScript += "<script language=\"javascript\" type=\"text/javascript\">\n";
          sScript += "alert(' Your Mail has been sent successfully ')\n";
          sScript += "window.close()";
          sScript += "</script>";
          run.InnerHtml = sScript;
          run.Visible = true;
          //Response.Write("Mail Sent");
      }
      catch (Exception ex)
      {
          Response.Write(ex.Message);
      }
      
      
        
    }
    public string mailbody(string name,string age,string location)
    {
       string mbody;
        mbody="";
        mbody+="Name:" + name + "<br />";
        mbody+="Age:" + age + "<br />";
        mbody+="Location:" + location + "<br />";
        return mbody;
    }
    
}
Posted
Updated 8-Feb-12 0:37am
v2

1 solution

I suspect the fact you're using a gmail address has something to do with this working sometimes and not others. Have you thought to try this with Outlook, or do you only care about webmail ? I'm not sure how doable this is, because it seems to me like the sort of thing that would be blocked, nowadays.
 
Share this answer
 
Comments
Siddhesh Patankar 8-Feb-12 10:06am    
Outlook doesnt work at all... If i click on the submit button in the E-mail it asks for a browser and when i select the browser it shows the homepage... Even i thought it was impossible at first... but it worked in gmail so i was hopeful it might work.... Actually i thinks its a completely new concept sending dynamic forms in mail
Christian Graus 8-Feb-12 10:07am    
It's certainly a concept that makes some assumptions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900