Click here to Skip to main content
15,890,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i want to know the code or the way , that i have designed a send an email using c#, in that i want to change the from address which is visible to the recipient. for example :
if i send a message to sss@gmail.com from sar@gmail.com means.
the sss@gmail.com receive the msg from dss@gmail.com instead of sar@gmail.com.
how to make this from address changes .my code is:
C#
try
            {
                MailMessage Msg = new MailMessage();
                // Sender e-mail address.
                Msg.From = new MailAddress(txtUsername.Text);
                // Recipient e-mail address.
                Msg.To.Add(txtTo.Text);
                Msg.Subject = txtSubject.Text;
                Msg.Body = txtBody.Text;
                // your remote SMTP server IP.
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com";
                smtp.Port = 587;
                smtp.Credentials=new System.Net.NetworkCredential(txtUsername.Text,txtpwd.Text);
                smtp.EnableSsl = true;
                smtp.Send(Msg);
                Msg = null;
<pre lang="xml">Page.RegisterStartupScript("UserMsg", "<script>alert('Mail sent thank you...');if(alert){ window.location='default.aspx';}</script>");
            }
            catch (Exception ex)
            {
            Console.WriteLine("{0} Exception caught.", ex);

}
}
Posted
Updated 22-Jun-14 20:28pm
v2
Comments
Thanks7872 23-Jun-14 2:43am    
Then what is the use of sar@gmail.com in this case? Why you take this into consideration at the first place?
sarosaran 23-Jun-14 3:15am    
sar@gmail.com know that he is sending msg to sss@gmail.com, but sss@gmail.com dont know the person who is that sar@gmail.com. its just to hide the from person identity.

Short Answer is No, you can't do this.
check This Answer[^] but you can add another email address to your Gmail account send using that. check this Link for more information.[^]
 
Share this answer
 
You Will Add One Properties

MailMessage mailMessage = new MailMessage(mailMessageModel.From, mailMessageModel.To);
MailAddress SenderID = new MailAddress("maheshpatil4357@gmail.com");
mailMessage.Sender = SenderID;


Or U need Make Email setting Dynamic Like
Set Email,Password,Port and Host Store it in Database
and Then Put Into Mail Message From Database
 
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