Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am use this code for sending mail, which is work fine but my problem is, when i receive mail using this code, i receive authentication mail id in from field,
but i want that, i use any mail id in from field so i reply esily on that mail id,
plz help me i try many code but all are use less

C#
using System.Net.Mail;
 
 private void MailSend()
        {
            try
            {
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");  
                SmtpServer.Host = "smtp.gmail.com";
 
                mail.From = new MailAddress("FromMailName@gamil.com");
                mail.To.Add("ToMailName@gmail.com");
                mail.Subject = "Test Mail";
                mail.Body = "This is for testing SMTP mail from GMAIL";
 
                SmtpServer.Port = 587;
 
                SmtpServer.Credentials = new System.Net.NetworkCredential("ToMailName@gmail.com", "123456"); // User Mail Name And Mail Password
                SmtpServer.EnableSsl = true;
 
                SmtpServer.Send(mail);              
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Posted
Updated 3-Dec-12 20:09pm
v2

1 solution

GMail only allows you to send mail from whoever is logged in. That way you can't send spam from their servers.

You'll have to stand up your own SMTP server or find another server that allows you to send mail on behalf of others.

You can try adding:

C#
mail.ReplyTo = "replytome@gmail.com";


Note: That method is deprecated for the ReplyToList method, use whichever you prefer.

See if they allow that.
 
Share this answer
 
v2
Comments
Arun kumar Gauttam 4-Dec-12 2:20am    
mailMessage.From = new MailAddress("me@mail-address.com", "My Name");

but when i use this it show my name on from field, but when i click on reply button it again take authentication mail id in to field
Expert Coming 4-Dec-12 2:30am    
Try my updated solution.
Arun kumar Gauttam 4-Dec-12 2:34am    
mail.ReplyToList.Add("me@mail-address.com");
i also try this but not work , what can i do,
can i change authntication of gmail to any other athontication, or it is not possible
Expert Coming 4-Dec-12 2:35am    
Nope. As far as I know, GMail doesn't allow you to have the message reply to anyone other than the authenticated user that sent the message.

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