Click here to Skip to main content
15,913,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello , in my web application i have one page contect us now in thare some filelds like name mobile no ,EMAIL ID msg, etc....now my coding look like
C#
protected void btn_sub_Click(object sender, EventArgs e)
    {
        try
        {
            MailMessage loginInfo = new MailMessage();
 
            loginInfo.From = new MailAddress(txt_eid.Text);
            loginInfo.To.Add("test@gmail.com");

            loginInfo.Subject = txt_sub.Text;
            loginInfo.IsBodyHtml = true;
            loginInfo.Body = "Name:-" + txt_name.Text + "<br><br>";
            loginInfo.Body += "Email Id:-" + txt_eid.Text + "<br><br>";
            loginInfo.Body += "Mobile No:-" + txtMobile.Text + "<br><br>";
            //loginInfo.Body += "Subject:-" + txt_sub.Text + "<br><br>";
            loginInfo.Body += "Message:-" + txt_msg.Text + "";


            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.EnableSsl = true;
            smtp.Credentials = new System.Net.NetworkCredential("test@gmail.com", "****");
 //here instead of test i have write my own EMail id  and password 
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtp.Send(loginInfo);
 
            Msg.Visible = true;
            Msg.Text = "Thanks for Contact us We will Contect You Very Soon";
 
            txt_name.Text = "";
            txt_eid.Text = "";
            txt_sub.Text = "";
            txt_msg.Text = "";
 
        }
        catch (Exception ex)
        {
            Msg.Visible = true;
            Msg.Text = "Your Message is Not Send";
            //ex.ToString();
        }
    }

now the code is working and mail is send to me...
now point to be noted is that means error is in my gmail account in both FROM and TO i have recive same email id that is My email id so i want customer's email id in from part....
Posted
Updated 5-Apr-13 22:42pm
v4

Check this link

http://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail[^]




write code like this

C#
loginInfo.From = new MailAddress(txt_eid.Text);

to
C#
loginInfo.From = new MailAddress("test@gmail.com","customeremailid@something.com/or/txt_eid.Text");
 
Share this answer
 
v2
Comments
pandya purvang 6-Apr-13 5:10am    
its not working........
Manu Thalasseril 6-Apr-13 5:36am    
if you want customer email id on 'from' part of gmail id you know the customer email id and also his password (that is impossible) . Remember you are sending this mail from your email id through programmatically..
Manu Thalasseril 6-Apr-13 5:45am    
or you can use a simple trick that replace 'from name' in the above link i given and type the customer email id
var fromAddress = new MailAddress("from@gmail.com","customeremailid@something.com/or/txt_eid.Text");
pandya purvang 6-Apr-13 6:31am    
yes i have put txt_eid.text in from address that u can show on my code.....but in body part i can get his/her email id....but in from part i m gatting my Email id only
Manu Thalasseril 6-Apr-13 6:52am    
write code like this

loginInfo.From = new MailAddress(txt_eid.Text);
to
loginInfo.From = new MailAddress("test@gmail.com","customeremailid@something.com/or/txt_eid.Text");

I have no problem with this code

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