[帮助]使用c#在asp.net中使用smtp同步Gmail [英] [Help] Sync Gmail using smtp in asp.net using c#

查看:69
本文介绍了[帮助]使用c#在asp.net中使用smtp同步Gmail的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的asp.net项目中的gmail帐户与c#的后端同步。现在我可以使用以下代码发送邮件:



  public   void  SendMail()
{
// 构建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 = new System.Net.Mail.Attachment(textBox4.Text);
msg.Attachments.Add(附件);

// 添加Creddentials
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential
(textBox1.Text, 密码);
client.Port = 587 ; // 或者使用587
client.Host = smtp.gmail.com ;
client.EnableSsl = true ;
client.SendCompleted + = new SendCompletedEventHandler
(client_SendCompleted);
object userState = msg;
尝试
{
// 你也可以调用client.Send(msg)
client.SendAsync(msg,userState);
}
catch (System.Net.Mail.SmtpException ex)
{
MessageBox.Show(ex.Message) , 发送邮件错误);
}
}





任何人都可以建议或链接我的代码,以便我可以同步我的Gmail我的Windows应用程序中的帐户??



我正在尝试制作一个像MS Outlook一样的Windows应用程序。

解决方案

这里似乎有两个不同的问题。在第一个你从ASP.NET发送邮件,你似乎工作。在第二步中,您尝试创建邮件客户端应用程序。您的邮件客户端需要实现SMTP,如 RFC 5321 [ ^ ],用于发送邮件。



[edit]

对于接收,您需要按照 RFC 1081 [ ^ ],正如Harvey在下面指出的那样。

[ /编辑]

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:

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.

解决方案

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]


这篇关于[帮助]使用c#在asp.net中使用smtp同步Gmail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆