拿出一半分50出来Help------------求jmail收gmail邮件代码或tcpclient的ssl收邮
拿出一半分50出来Help
求 C# jmail收gmail邮件代码,或tcpclient的ssl收邮
顶者有小小分.解决都拿去50中的40.分一些给别人吧...
天天上来顶
------解决方案--------------------帮不了你了我只有JMAIL发邮件的没有收邮件的
------解决方案--------------------gmail代码?
public class MyMail
{
public static void SendMail(string strSmtpServer, string strFrom, string strFromPass, string strto, string strSubject, string strBody,bool ssl,int port)
{
SmtpClient client = new SmtpClient(strSmtpServer, port);
//client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass);
//client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = ssl;
MailMessage message = new MailMessage(strFrom, strto, strSubject, strBody);
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
client.Send(message);
}
public static void SendMail(string strto, string strSubject, string strBody)
{
SendMail( "smtp.gmail.com ", "sean.pu@gmail.com ", "yourpassword ", strto, strSubject, strBody, true, 587);
}
}
------解决方案--------------------这是发邮件的。接受邮件?我没测试过
不过你可以google it
------解决方案--------------------using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net.Sockets;
using System.Net.Security;
using System.Threading;
namespace GmailTest
{
class Program
{
static void Main(string[] args)
{
PopClient( "pop.gmail.com ",995, "用户名 ", "密码 ");
Console.Read();
}
static int PopClient(string serverAddr,int port,string userID,string password)
{
TcpClient clientSocket = new TcpClient();
StreamReader reader;
StreamWriter writer;
Stream pop3Stream;
clientSocket.Connect(serverAddr, port);
pop3Stream = new SslStream(clientSocket.GetStream(),false);
((SslStream)pop3Stream).AuthenticateAsClient(serverAddr); //这句是用来客户端验证的
reader = new StreamReader(pop3Stream, Encoding.Default, true);
writer = new StreamWriter(pop3Stream);
writer.AutoFlush = true;
Read(ref reader); //判断我省略了^_^
SendCommand(ref writer, "USER " + userID);
Read(ref reader);
SendCommand(ref writer, "PASS " + password);
Read(ref reader);
SendCommand(ref writer, "STAT ");
Read(ref reader);
SendCommand(ref writer, "LIST 1 "); //随意写的
Read(ref reader);
SendCommand(ref writer, "TOP 1 20 "); //随意写的
SendCommand(ref writer, "QUIT ");
Read(ref reader);
reader.Close();
writer.Close();
clientSocket.Close();
return 0;
}
static bool Read(ref StreamReader reader)
{
string strResponse;
while (!reader.BaseStream.CanRead)