Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I'm Trying to Sync my gmail account in my asp.net project with back end of c#. Right now I can just send mail using the code:

C#
public void SendMail()
        {
            //Build The MSG
            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
            
            msg.To.Add(textBox2.Text);
            msg.From = new MailAddress(textBox1.Text);
            msg.Subject = textBox3.Text;
            msg.SubjectEncoding = System.Text.Encoding.UTF8;
            msg.Body = richTextBox1.Text;
            msg.BodyEncoding = System.Text.Encoding.UTF8;
            msg.IsBodyHtml = false;
            msg.Priority = MailPriority.High;
            System.Net.Mail.Attachment attachment;
            attachment = new System.Net.Mail.Attachment(textBox4.Text);
            msg.Attachments.Add(attachment);

            //Add the Creddentials
            SmtpClient client = new SmtpClient();
            client.Credentials = new System.Net.NetworkCredential
                (textBox1.Text, "Password");
            client.Port = 587;//or use 587            
            client.Host = "smtp.gmail.com";
            client.EnableSsl = true;
            client.SendCompleted += new SendCompletedEventHandler
                (client_SendCompleted);
            object userState=msg;
            try
            {
                //you can also call client.Send(msg)
                client.SendAsync(msg, userState);                
            }
            catch (System.Net.Mail.SmtpException ex)
            {
                MessageBox.Show(ex.Message, "Send Mail Error");
            }
        }


Can any one suggest or link me with the code so that i can sync my gmail account in my windows app ??

I'm trying to make an windows app just like MS outlook.
Posted

1 solution

You seem to have two different issues here. In the first you are sending mail from ASP.NET, which you seem to have working. In the second you are trying to create a mail client application. Your mail client will need to implement SMTP as described in RFC 5321[^], for sending mail.

[edit]
For receiving you need to look at the POP3 protocol as described in RFC 1081[^], as Harvey points out below.
[/edit]
 
Share this answer
 
v2
Comments
H.Brydon 14-Sep-13 20:53pm    
You said SMTP but I think you probably meant POP3 or IMAP (and correspondingly different RFCs).
Richard MacCutchan 15-Sep-13 3:34am    
You are right of course, thanks.

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