Several different email sends a solution in .NET Environment
1. Use Outlook to provide transmission
Such as: I have seen UF Software U8 Production (Demo Edition), where the mail function is to call the Outlook ActiveX component
Advantages: Simple development
Disadvantages: Relying on Outlook Components, SMTP Mail Services
The code sent by the mail is as follows:
Private subsessment ()
Dim outobj as new outlook.Application ()
Dim item as outlook.mailItemclass
Item = Outobj.createItem (0)
Item.to = "
Lihonggen0@163.com
"
Item.subject = "Hello"
Item.body = "hell"
Item.attachments.add ("c: /abc.txt")
Item.send ()
End Sub
Reference: Using Microsoft Outlook 2002 Development Solution Http://www.microsoft.com/china/msdn/library/dndotNetOut2k2/HTML/odc_oldevsol.asp
2, web development, reference system.web.mail class in ASP.NET
System.Web.mail Namespace contains classes that enable you to construct and send messages using CDOSYS (Wildows 2000 Collaboration Data Object) messages. The mail message is transmitted by built-in SMTP mail service or any SMTP server in Microsoft Windows 2000. Classes in this namespace can be in ASP.NET or any hosting application
MaiLattachment provides properties and methods for constructing email attachments.
MailMessage provides properties and methods for constructing email.
SMTPMAIL provides properties and methods for sending messages using the Collaboration Data Objects (CDOSYS) message components of Windows 2000.
The message can be transmitted through the SMTP mail service or any SMTP server built in Microsoft Windows 2000. The type in System.Web.mail Namespace can be used in ASP.NET or any hosting application.
SMTP server settings, now some free mail providers are no longer providing all emails to provide SMTP services, when sending mail, you need to verify user information, consider SMTP user authentication issues
If the SMTP server is in the local computer, the transmission speed is very fast, basically don't worry, if it is not a local server, then it is best not to use this time, one is the speed problem, the second is to send too many emails, SMTP Server may think is spam and refusal service
code show as below:
Private sub button1_click (byvale 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.163.com"
'Defining the send address of the message
Mailobj.from = "lihonggen@163.com"
'Define the receiving address of the message
Mailobj.to = "
Lihonggen0@163.com
"
'Defining the Dark Address of Mail
'Mailobj.bcc "aa@sina.com"' Defines the copy address of the message
'Mailobj.cc = "aaa@sina.com"
'Defining the subject of the email
Mailobj.subject = "Theme"
'Defining the subject of the mail
Mailobj.Body = "Mail body!"
'Mail is sent in HTML format
Mailobj.BodyFormat = mailformat.html
'Define the limited number of emails, set it high here
Mailobj.Priority = mailpriority.high
'Additional attachments to send mail
Mailobj.attachments.Add (New MaiLattachment ("C: /Lihonggen.doc")))
SMTP.SEND (Mailobj)
End Sub
3, use system.net.sockets in VB.NET or C # development Windows applications
Also based on the SMTP protocol
1. Introduction to the SMTP Protocol
1. Establish TCP / IP connection through the 25-port of the server
Server: 220 Server.com Simple Mail Transfer Service Ready
2, the client uses "helo" command to identify the sender
Client: Helo Server.com
Server: 250 Server.com
3, the client sends the mail command, the server side is in response to the response to the reception
Server side: 250 ok
4, the client sends the RCPT command to identify the recipient, the server side responds if it is willing to accept mail for the recipient
Client: rcpt to:
Server side: 250 ok
5. After the negotiation is over, use the command DATA to send the mail.
Client: DATA
Server: 354 Start Mail INPUT: End with
6, the client is. Representing the end of the input content
Client: Subject:
Content
7, the client exits with the Quit command.
Client: quit
Server: 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 is relatively large,
The code to send the message is as follows:
Dim Senddata As String
DIM SZDATA AS BYTE ()
DIM CRLF AS STRING
CRLF = "/ r / n"
'Creating a connection to the server 25 port
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 () <> "" "" "" "" "
'
Senddata = "Helo Server" CRLFSZDATA = System.Text.Encoding.ascii.getBytes (Senddata.toChararray ())
NetStrm.write (szdata, 0, szdata.length)
Lstlog.Items.Add (RDStrm.Readline ())
'Sign 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 ())
'Logo recipient
Senddata = "RCPT TO:" <" TXTTTTO.TEXT "> CRLF
Szdata = system.text.Encoding.ascii.getbytes (Senddata.tochararray ())
NetStrm.write (szdata, 0, szdata.length)
Lstlog.Items.Add (RDStrm.Readline ())
'Ready 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 the subject
Senddata = "SUBJECT: TXTSUB.TEXT CRLF
'Send Content
Senddata = sendData TXTMSG.Text CRLF
'End send
Senddata = sendData "." CRLF
Szdata = system.text.Encoding.ascii.getbytes (Senddata.tochararray ())
NetStrm.write (szdata, 0, szdata.length)
Lstlog.Items.Add (RDStrm.Readline ())
'drop out
Senddata = "quit" CRLF
Szdata = system.text.Encoding.ascii.getbytes (Senddata.tochararray ())
NetStrm.write (szdata, 0, szdata.length)
Lstlog.Items.Add (RDStrm.Readline ())
'Close connection
Netstrm.close ()
Rdstrm.close ()
Lstlog.Items.Add ("¿¿关 闭")
Lstlog.Items.Add ("Send Success")
You can also refer to: Create a mail sending component (SMTP) using C #
Http://www.aspcool.com/lantmu/browse1.asp?id=968&bbsuser=csharp
4, IIS SMTP comes with the basic letter component CDONTS you don't have to download, Microsoft has provided this component, as long as the 2000, NT's SMTP will have.
Advantages: Components comes from the operating system
Disadvantages: the function is poor, the scalability is not strong
Mymail = creteObject ("cdonts.newmail")
Mymail.from = *** 'Letter sender mailbox
Mymail.to = *** 'Letter Receiver Mailbox
Mymail.cc = *** 'Cc
Mymail.bcc = *** 'Delivery
Mymail.subject = *** 'Letter Theme
Mymail.body = *** 'letter body
'Setting the priority, 0- is not important, 1-general, 2- important.
MyMail.Importance = 2
Mymail.send ()
Mymail = Nothing
5, use JMail components
Jmail has the following features:
(1) You can send an attachment; (2) Detailed logging ability, easy to see the problem; (3) Set the priority of mail delivery; (4) Support for multiple formats, such as HTML or TXT transmission mail. This is a free component. (5) Delivery / (CC) Cc / Emergency Letters; (6) The most critical is - free components, don't make money, so it is worthwhile.
Website: http://www.dimac.net/, the current version is 4.3
The common attribute of the JMail component:
Body mail body
Logging call log record for Debug
Priority email priority, from 1 to 5
Sender sender
IP address or name of the ServerAddress SMTP server
Subject mail title
Common methods for JMail components:
Addattachment Specifies an attachment file
AddRecipient Add to a Recipient
AddRecipientBCC hidden copy Cc, only the sender and BCC recipient know.
AddRecipientcc copy Cc
Execute sent out mail
After understanding the necessary properties and methods, the remaining part receives the Email entered by the user, transmitting the remaining attribute as needed, and then fill in the execute method. E.g:
DIM JMAIL
Jmail = Server.createObject ("jmail.smtpmail")
Jmail.logging = true
Jmail.Serveraddress = "202.96.144.48"
Jmail.Sender = "
Lihonggen0@163.com
"
Jmail.subject = "Subject."
Jmail.Body = "body."
Jmail.Addrecipient ("bbbb@163.com")
Jmail.Addattachment ("c: /GO.gif")
Jmail.priority = 3
Jmail.execute ()
Jmail = Nothing
Summary: What kind of program, the use and demand of the proceedings, and several programs in this article are available for your reference. For example, UF software U8, call Outlook Components, integrate into their own software. I have written the management system, write component (SMTP), the function is equally powerful, but the Coding time is long! Note: This article has a small number of information extracted
Author: Li Honggen
E_mail:
Lihonggen0@163.com