1. Use the sending software provided by outLook, such as the UFIDA software U8 Manufacturing (demo version) I have seen, in which the email function is sent by calling the ActiveX component of outLook. Advantages: Simple development. Disadvantages: Relying on the outlook component, SMTP mail service
to send emails. The code is as follows:
Private Sub Send()
Dim outObj As New Outlook.Application()
Dim Item As Outlook.MailItemClass
Item = outObj.CreateItem(0)
Item.To = "
[email protected] "
Item.Subject = "hello"
Item.Body = "hell"
Item.Attachments.Add("C:abc.txt")
Item.Send()
End Sub
2. WEB development, refer to System.Web.Mail in ASP.NET kind
The System.Web.Mail namespace contains classes that enable you to construct and send messages using the CDOSYS (Collaboration Data Objects for Windows 2000) message component. Mail messages are delivered through the SMTP mail service built into Microsoft Windows 2000 or through any SMTP server. Classes in this namespace can be used in ASP.NET or any managed application
MailAttachment provides properties and methods for constructing email attachments.
MailMessage provides properties and methods for constructing email messages.
SmtpMail provides properties and methods for sending messages using the Collaboration Data Objects (CDOSYS) message component of Windows 2000.
Mail can be delivered through the SMTP mail service built into Microsoft Windows 2000 or through any SMTP server. Types in the System.Web.Mail namespace can be used in ASP.NET or any managed application.
Smtp server settings. Now some free email providers no longer provide Smtp services for all emails. When sending emails, user information needs to be verified. Consider the Smtp user verification issue. If the Smtp server is on the local computer, the sending speed will be very fast. , basically don’t worry. If it is not a local server, it is best not to use it too much when sending. One is the speed problem, and the other is sending too many emails. The Smtp server may think it is spam and the denial of service code is as follows:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mailObj As New MailMessage()
Dim smtp As SmtpMail
'Define the name of the SMTP server
smtp.SmtpServer = "smtp.XXX.com"
'Define the email sending address
mailObj.From = "
[email protected] "
'Define the email receiving address
mailObj.To = "
[email protected] "
'Define the BCC address of the email
mailObj.Bcc= "
[email protected] "
'Define the carbon copy address of the email
mailObj.Cc = "
[email protected] "
'Define the subject of the email
mailObj.Subject = "Subject"
'Define the body of the email
mailObj.Body = "Mail body!"
'The email is sent in HTML format
mailObj.BodyFormat = MailFormat.Html
'Define the limited level of mail, set it to high here
mailObj.Priority = MailPriority.High
'Attach an attachment to the sent email
mailObj.Attachments.Add(New MailAttachment("c:aa.doc"))
smTp.Send(mailObj)
End Sub
3. Use System.Net.Sockets in developing Windows applications in VB.NET or C#
It is also based on SMTP protocol 1. Introduction to SMTP protocol
1. The client establishes a TCP/IP connection to the server through port 25 of the server: 220 server.com Simple Mail Transfer Service Ready
2. The client uses the "HELO" command to identify the sender client: HELO server.com
Server side: 250 server.com
3. The client sends a MAIL command, and the server responds with OK to indicate that it is ready to receive the client: MAIL FROM: <
[email protected] >
Server side: 250 OK
4. The client sends the RCPT command to identify the recipient, and the server responds whether it is willing to accept the email client for the recipient: RCPT TO: <
[email protected] >
Server side: 250 OK
5. After the negotiation is completed, use the command DATA to send the email client: DATA
Server side: 354 Start mail input: end with <CRLF>.<CRLF>
6. The client ends the input content with . and sends it to the client: Subject: <CRLF>
Content<CRLF>
.<CRLF>
7. The client exits using the QUIT command.
Client: QUIT
Server side: 250 server.com closing transmission channel
Advantages: You can develop your own components on this basis. Using Sockets, we can develop network programming. Disadvantages: The amount
of program is relatively large. The code for sending emails is as follows:
Dim sendData As String
Dim szData As Byte()
Dim CRLF As String
CRLF = "rn"
'Create a connection to the server port 25
Dim SmtpServ As New TcpClient(txtsmtp.Text, 25)
lstlog.Items.Clear()
'Display server initial information
Dim NetStrm As NetworkStream
NetStrm = SmtpServ.GetStream()
Dim RdStrm As New StreamReader(SmtpServ.GetStream())
If RdStrm.ReadLine() <> "" Then lstlog.Items.Add(RdStrm.ReadLine())
'
sendData = "HELO server " + CRLF
szData = System.Text.Encoding.ASCII.GetBytes(sendData.ToCharArray())
NetStrm.Write(szData, 0, szData.Length)
lstlog.Items.Add(RdStrm.ReadLine())
'Mark sender
sendData = "MAIL FROM: " + "<" + txtfrom.Text + ">" + CRLF
szData = System.Text.Encoding.ASCII.GetBytes(sendData.ToCharArray())
NetStrm.Write(szData, 0, szData.Length)
lstlog.Items.Add(RdStrm.ReadLine())
'Mark recipient
sendData = "RCPT TO: " + "<" + txtTo.Text + ">" + CRLF
szData = System.Text.Encoding.ASCII.GetBytes(sendData.ToCharArray())
NetStrm.Write(szData, 0, szData.Length)
lstlog.Items.Add(RdStrm.ReadLine())
'Prepare to send content
sendData = "DATA " + CRLF
szData = System.Text.Encoding.ASCII.GetBytes(sendData.ToCharArray())
NetStrm.Write(szData, 0, szData.Length)
lstlog.Items.Add(RdStrm.ReadLine())
'Send topic
sendData = "SUBJECT: " + txtsub.Text + CRLF
'Send content
sendData = sendData + txtmsg.Text + CRLF
'End sending
sendData = sendData + "." + CRLF
szData = System.Text.Encoding.ASCII.GetBytes(sendData.ToCharArray())
NetStrm.Write(szData, 0, szData.Length)
lstlog.Items.Add(RdStrm.ReadLine())
'Exit
sendData = "QUIT " + CRLF
szData = System.Text.Encoding.ASCII.GetBytes(sendData.ToCharArray())
NetStrm.Write(szData, 0, szData.Length)
lstlog.Items.Add(RdStrm.ReadLine())
'Close the connection
NetStrm.Close()
RdStrm.Close()
lstlog.Items.Add("Connection closed")
lstlog.Items.Add("Sent successfully")
You can also refer to: Using C# to create an email sending component (SMTP)
http://www.aspcool.com/lanmu/browse1.asp?ID=968&bbsuser=csharp 4. CDONTS, the basic sending component that comes with IIS SMTP
You don't need to download it specifically. Microsoft has already provided this component. As long as 2000 is installed, NT's SMTP will have it.
Advantages: The components are provided by the operating system. Disadvantages: Poor functionality and poor scalability.
Mymail = CreateObject("CDONTS.NewMail")
Mymail.From = *** 'Mailbox of the sender of the letter
Mymail.To = *** 'Mailbox of the recipient of the letter
Mymail.CC = *** 'Cc
Mymail.BCC = *** 'Bind send
Mymail.Subject = *** 'Subject of the letter
Mymail.Body = *** 'Body of the letter
'Set the priority, 0-not important, 1-general, 2-important.
Mymail.Importance = 2
Mymail.Send()
Mymail = Nothing
5. Use JMail component
Jmail has the following characteristics:
(1) Attachments can be sent;
(2) Detailed log capability allows you to check the problem;
(3) Set the priority of email sending;
(4) Supports sending emails in multiple formats, such as sending emails in HTML or TXT. This is a free component.
(5) The ability to send blind emails/(CC) carbon copies/urgent letters;
(6) The most important thing is - the components are free and you don’t have to pay for them, so they are very worth using.
Website:
http://www.dimac.net/ , the current version is 4.3.
Common attributes of JMail components:
Body Email body
Logging calls Log recording for Debug use
Priority The priority of the email, from 1 to 5
Sender sender
ServerAddress IP address or name of the SMTP server
Common methods of
Subject email title
JMail component:
AddAttachment specifies the attachment file
AddRecipient adds a recipient
AddRecipientBCC Hidden copy, known only to the sender and BCC recipients.
AddRecipientCC CC
After Execute sends the email
and understands the necessary attributes and methods, the remaining part receives the email entered by the user and passes it as a parameter to the AddRecipient method, then fills in the remaining attributes as needed, and finally sends it with the Execute method. For example:
Dim JMail
JMail = Server.CreateObject("JMail.SMTPMail")
JMail.Logging = True
JMail.ServerAddress = "202.96.144.48"
JMail.Sender = "
[email protected] "
JMail.Subject = "subject."
JMail.Body = "body."
JMail.AddRecipient("
[email protected] ")
JMail.AddAttachment("c:go.gif")
JMail.Priority = 3
JMail.Execute()
JMail = Nothing
summary: Which solution to choose depends on the purpose and needs of the program. This article provides several examples for your reference. For example, UFIDA software U8 calls the Outlook component and integrates it into its own software. The management system I wrote, I wrote my own components (SMTP), is equally powerful, but the coding time is longer!