In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to use C# to send mailboxes, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
1. Simple email delivery (without authorization code)
Secure connections are not started here, and some mailboxes do not support secure connections.
/ / the most basic way to send mail
/ / /
Public static void Send163Demo ()
{
String user = "asdf@qq.com"; / / replace with your hotmail user name
String password = "1234"; / / replace with your hotmail password
String host = "smtp.qq.cn"; / / set the server for mail
String mailAddress = "asdf@qq.com"; / / replace it with your hotmail account
String ToAddress = "lsd@qq.com"; / / destination email address.
SmtpClient smtp = new SmtpClient (host)
/ / smtp.EnableSsl = true; / / Open a secure connection.
Smtp.Credentials = new NetworkCredential (user, password); / / create user credentials
Smtp.DeliveryMethod = SmtpDeliveryMethod.Network; / / transmit over the network
MailMessage message = new MailMessage (mailAddress, ToAddress, "title", "send content"); / / create a message
Smtp.Send (message); / / send email asynchronously smtp.SendAsync (message, "huayingjie"); / / with a simple modification here, sending email will change very quickly.
MessageBox.Show ("email sent successfully!")
}
Secure connection to send mailbox (with authorization code)
# region QQ Mail email delivery
/ / pub.SendMail email = new pub.SendMail (); / / new an object after referencing the namespace in which this class resides
/ / string _ sendServer = "smtp.qq.com"; / / Server address
/ / string _ sendUseremail = "123213@qq.com"; / / Sender mailbox
/ string _ sendUserGrant = "hxtl2hbicj"; / / authorization code
/ / string _ sendToUser = "12321323@qq.com"; / / recipient
/ / string _ strSubject = "Digital Purchasing system KPI push-PP"; / / theme
/ / string _ strBody = string.Empty;// sent content
/ / for (int I = 0; I < list_user.Count; iTunes +)
/ / {
/ / if (list_ user [I] .email! = "")
/ / _ sendToUser + = "," + list_ user [I] .email
/ /}
/ message content header
/ / _ strBody + = "Hello, everyone! the following is the KPI summary of the PP module:"
/ the middle section-get the form
/ / _ strBody + = getMailBody_PP (a)
/ / the end of the email content
/ / _ strBody + = "Please pay attention to the content items that have not been reached and hope to finish them today."
/ email.SendQQMail ("smtp.qq.com", "2342@qq.com", "234234", "23432@qq.com", "QQ Mail server sends mail", "send mail with asp.net, use QQ's smtp.qq.com server, the test is successful")
/ / email.SendQQMail (_ sendServer, _ sendUseremail, _ sendToUser, _ strSubject, _ strBody)
# endregion
}
Services with authorization codes
Using System
Using System.Collections.Generic
Using System.Linq
Using System.Net
Using System.Net.Mail
Using System.Text
Using System.Threading.Tasks
Namespace SendMail.pub
{
Class SendMail
{
/ / public void SendQQMail (string strSmtpServer, string strFrom, string strto
/ / string strSubject, string strBody)
/ / {
/ / SmtpClient smtpClient = new SmtpClient ()
/ / smtpClient.EnableSsl = true
/ / smtpClient.UseDefaultCredentials = false;// set first
/ / smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; / / specify how to send email
/ / smtpClient.Host = strSmtpServer; / / specify SMTP server
/ / smtpClient.Credentials = new System.Net.NetworkCredential (strFrom, strFromPass); / / user name and authorization code
/ send mail settings
/ / MailMessage mailMessage = new MailMessage (strFrom, strto); / / sender and recipient
/ / mailMessage.Subject = strSubject; / / topic
/ / mailMessage.Body = strBody;// content
/ / mailMessage.CC.Add ("liujihui@shinbada.com")
/ / mailMessage.BodyEncoding = Encoding.UTF8; / / text coding
/ / mailMessage.IsBodyHtml = true; / / set to HTML format
/ / mailMessage.Priority = MailPriority.Low; / / priority
/ / smtpClient.Send (mailMessage)
/ /}
/ / /
/ send an email
/ / /
/ / /
/ / /
Public static bool SendALLMail (MailModel model)
{
Try
{
MailAddress receiver = new MailAddress (model.ReceiverAddress, model.ReceiverName)
MailAddress sender = new MailAddress (model.SenderAddress, model.SenderName)
MailMessage message = new MailMessage ()
Message.From = sender;// Sender
Message.To.Add (receiver); / / recipient
/ / message.CC.Add (sender); / / CC
Message.Subject = model.Title;// title
Message.Body = model.Content;// content
Message.IsBodyHtml = whether true;// supports the content of HTML
SmtpClient client = new SmtpClient ()
Client.Host = "smtp.qq.com"
Client.Port = 465
Client.EnableSsl = whether SSL is enabled for true;//
Client.Timeout = 10000 position / timeout
Client.DeliveryMethod = SmtpDeliveryMethod.Network
Client.UseDefaultCredentials = false
Client.Credentials = new NetworkCredential (model.SenderAddress, model.SenderPassword)
Client.Send (message)
Return true
}
Catch (Exception e)
{
Return false
}
}
}
}
Table field
Public struct MailModel
{
/ / /
/ / recipient address
/ / /
Public string ReceiverAddress {get; set;}
/ / /
/ / recipient's name
/ / /
Public string ReceiverName {get; set;}
/ / /
/ / title
/ / /
Public string Title {get; set;}
/ / /
/ / content
/ / /
Public string Content {get; set;}
/ / /
/ / Sender address (optional)
/ / /
Public string SenderAddress {get; set;}
/ / /
/ / Sender's name (not required)
/ / /
Public string SenderName {get; set;}
/ / /
/ / Sender password (optional)
/ / /
Public string SenderPassword {get; set;}
Public string host {get; set;}
}
On how to use C# to send mailboxes to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.