In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "how to send and receive email in C#", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to send and receive email in C#" article.
1. Server TcpListener server = new TcpListener (IPAddress.Parse ("127.0.0.1"), 13000); / / define listener server.Start (); / / start listener byte [] buffer = new byte [1024]; / / create a container to receive data string data = null; while (true) {/ / wait for the client to connect to TcpClient client = server.AcceptTcpClient () / / Task task1 = server.AcceptTcpClientAsync (); / / Socket socket = server.AcceptSocket (); / / Task task2 = server.AcceptSocketAsync (); / / server.Pending (); / / get the data sent by the client int len = client.Available;// get the amount of data that has been received from the network stream and available for reading NetworkStream nstream = client.GetStream () / / returns a network stream int bytesRead; do {bytesRead = nstream.Read (buffer, 0, buffer.Length) that can be read and written; / / receives the message data = Encoding.UTF8.GetString (buffer, 0, bytesRead); / / converts the received data into an outputable string type Console.WriteLine ("received message:" + data) Output received information byte [] msg = Encoding.UTF8.GetBytes (data.ToUpper ()); nstream.Write (buffer, 0, buffer.Length); / / send message} while (bytesRead > 0); nstream.Close (); / / 1. First release the streaming data client.Close (); / / 2. Then release the client connection data} server.Stop (); / / 3. Turn off listening II. Client TcpClient client=new TcpClient ("127.0.0.1", 13000); / / connect to the server / / or / TcpClient client=new TcpClient (); / / client.Connect ("127.0.0.1", 13000); NetworkStream nstream = client.GetStream (); / /-other same server nstream.Close (); / / 1. First release the streaming data client.Close (); / / 2. Then release the connection data of the client 3, send mail 1, use MailMessage and SmtpClient to send mail.
In Wince, you can use the OpenNetCF.Net.Mail class to send messages.
MailMessage mailMessage = new MailMessage {/ / Sender From = new MailAddress ("* @ 163.com", "your friend", Encoding.UTF8), Priority = MailPriority.High, / / email subject SubjectEncoding = Encoding.UTF8, Subject = "Hello",} / / recipients can add multiple recipients mailMessage.To.Add (new MailAddress ("137***126@qq.com")); / / mailMessage.CC gets the address collection of CC recipients containing this email / / message body mailMessage.IsBodyHtml = true;// if you want to send a message in html format, you need to set this property mailMessage.BodyEncoding = Encoding.UTF8 MailMessage.Body = "Mail Test
"; / / the content of the message means that the picture is displayed in the body of the message. You need to specify src='cid:idname (resource id) 'AlternateView htmlBody = AlternateView.CreateAlternateViewFromString ("
", null," text/html "); / / then add the absolute address of the file in LinkedResource, and ContentType such as image/gif,text/html... Consistent with the ContentType in the response message of the http request LinkedResource lr = new LinkedResource ("1.gif", "image/gif"); / bind idname lr.ContentId = "zfp" specified above; / / add link resource htmlBody.LinkedResources.Add (lr); mailMessage.AlternateViews.Add (htmlBody); / / send the attachment to indicate the absolute address of the attachment Attachment attachment = new Attachment ("1.txt") MailMessage.Attachments.Add (attachment); / / create email sending client SmtpClient sendClient = new SmtpClient ("smtp.qq.com", 25) {/ / specify mailbox account and password Credentials = new NetworkCredential (fromMail, "xmxyldrmtvnrddfe")}; / / specify how to send email sendClient.DeliveryMethod = SmtpDeliveryMethod.Network / specify the link sendClient.EnableSsl = true; sendClient.Send (mailMessage) encrypted using secure socket ssl; / / or send sendClient.SendAsync (mailMessage, null) in one step; 2. Use TcpClient class to receive pop3 email TcpClient client = new TcpClient ("mail.**.com", 443); / / connect NetworkStream ns = client.GetStream (); StreamReader sr = new StreamReader (ns, Encoding.Default) String result = sr.ReadLine (); / / return OK or ER / / Log in StreamWriter sw = new StreamWriter (ns); sw.WriteLine ("user breadth *"); sw.Flush (); result = sr.ReadLine (); sw.WriteLine ("pass * *"); sw.Flush (); result = sr.ReadLine (); / / get the number of messages sw.WriteLine ("stat"); sw.Flush () Result = sr.ReadLine (); / / result.split ('') [1] indicates the number of messages / / get email information sw.WriteLine ("top 1 0"); sw.Flush (); result = sr.ReadLine (); while (true) {result = sr.ReadLine (); if (result = ".") Break; if (result.Length > 4 & & result.Substring (0,8) = = "Subject:") {/ / result is the title, and Base64 is used to decode Encoding.GetEncoding ("gb2312") .GetString (Convert.FromBase64String (result)) }} the above is the content of this article on "how to send and receive email in C#". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.