Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to get the automatic reply mail from mail2. here is the code.

C#
string from = "noreplymail@gmail.com";
       string to = "mail2@gmail.com";
       string Password = "password123";
       int port = Convert.ToInt32(ConfigurationManager.AppSettings["port"]);
       string smtp = Convert.ToString(ConfigurationManager.AppSettings["smtp"]);
       string Subject = "Enquiry";
       string body = "Sender Name :" + txtname.Text + "\n" +
                    "Phone :" + txtphone.Text + "\n" +
                    "Email :" + txtemail.Text + "\n" +
                    "Address :" + txtaddress.Text + "\n"
                    + "Enquiry :" + txtenquiry.Text;
       string fromr = "mail2@gmail.com";
       string tor = txtemail.Text;
       string reply = "Enquiry feedback";
       string bbdy = "soon in touch";
       MailMessage Msg = new MailMessage(from, to, Subject, body);
       MailMessage replyMsg = new MailMessage(fromr, tor, reply, bbdy);
       //Smtp Host is the  name or Ip host of the computer used for sending mail
       SmtpClient smtpobj = new SmtpClient("smtp.gmail.com", 587);
       smtpobj.Host = "smtp.gmail.com";
       smtpobj.Port = 587;
       smtpobj.EnableSsl = true;
       smtpobj.UseDefaultCredentials = false;
       smtpobj.Credentials = new System.Net.NetworkCredential(from, Password);

       try
       {
           smtpobj.Send(Msg);
           smtpobj.Send(replyMsg);

       }
       catch (Exception ex)
       {

       }



but i am getting reply automatic response from noreplymail@gmail.com , i need to get reply from mail2@gmail.com. help me how to code...
Posted
Updated 17-Apr-15 23:39pm
v3

1 solution

How much i understand you question is you are getting reply from wrong source as you want reply from the same email you specified above

C#
string from = "noreplymail@gmail.com";
string to = "mail2@gmail.com";
string Password = "password123";
int port = Convert.ToInt32(ConfigurationManager.AppSettings["port"]);
string smtp = Convert.ToString(ConfigurationManager.AppSettings["smtp"]);
string Subject = "Enquiry";
string body = "Sender Name :" + txtname.Text + "\n" +
"Phone :" + txtphone.Text + "\n" +
"Email :" + txtemail.Text + "\n" +
"Address :" + txtaddress.Text + "\n"
+ "Enquiry :" + txtenquiry.Text;

//You dont need to provide from mail again as you have specified above
//string fromr = "mail2@gmail.com";

string tor = txtemail.Text;

string reply = "Enquiry feedback";
string bbdy = "soon in touch";
MailMessage Msg = new MailMessage(from, to, Subject, body);

//change 'fromr' to 'to'
MailMessage replyMsg = new MailMessage(to, tor, reply, bbdy);
 
Share this answer
 

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