Several different email sends a solution in .NET Environment

xiaoxiao2021-03-06  147

code:

Several different emails in the .NET environment 1, using Outlook, send such as: I have seen UF Software U8 Production Manufacturing (Demo Edition), where the mail function is to use the advantages of Outlook ActiveX Components: Simple development disadvantages: outlook dependent component, code SMTP mail messages sent by the service follows: Private Sub send () 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 Solutions

http://www.microsoft.com/china/msdn/library/dndotnetOut2k2/html/odc_oldevsol.asp

2, web development, reference system.Web.mail class system.Web.mail namespace in ASP.NET contains classes that enable you to construct and send messages using CDOSYS (Wildows 2000 Collaboration Data Object) Messaging components. The mail message is transmitted by built-in SMTP mail service or any SMTP server in Microsoft Windows 2000. Classes in this namespace can provide properties and methods for constructing email attachments in ASP.NET or any hosting application mailettachment. 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 available to provide SMTP services for all messages, when sending mail, you need to verify user information, consider SMTP user authentication If the SMTP server is on the local computer, the transmission speed is very fast It is basically not worried. If it is not a local server, it is best not to use this time when sending, one is the speed problem, the second is to send too many mail, the SMTP server may think is spam and the refusal 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 () name smtp.SmtpServer Dim smtp As SmtpMail 'defined SMTP server = "smtp.163.com" 'Defining the send address of the message mailobj.from = "lihonggen@163.com"' Defines the message of the message mailobj.to = "lihonggen0@163.com" 'Defines the message of the message' Mailobj.bcc "aa @ sina. COM "'Defines the message of the message' Mailobj.cc =" aaa@sina.com "'Defines the subject mailobj.subject =" Theme "' Defines the mail of the mail Mailobj.Body =" Mail body! "' HTML format Sends Mailobj.BodyFormat = MailFormat.html 'Defines the limited number of emails, set to high milobj.Priority = mailpriority.high' Add an attachment Mailobj.attachments.Add (new mailattachment) C: /lihonggen.doc ")) SMT P.send (Mailobj) End Sub 3, using system.net.sockets in VB.NET or C # Developing Windows applications is also based on SMTP protocol 1, SMTP protocol introduction 1. Connect TCP / IP connection through the 25-port of the server Server: 220 Server.com Simple Mail Transfer Service Ready2, the client uses the "helo" command ID Sender client: Helo Server.com server: 250 server.com3, the client sends a mail command, the server side is as OK Response indicates that the client: mail from: server side: 250 ok4, the client sends the RCPT command to identify the recipient, the server side responds to whether to accept the mail client for the recipient: RCPT TO: Server: 250 ok5, after the negotiation ends, use the command data to send the mail client:

DATA server side: 354 Start mail input: End with . 6, the client is. Representing the end of the input content together, send out the client: Subject: content . 7, customer The terminal exits with the Quit command.

Client: Quit Server: 250 Server.com Closing Transmission Channel Advantages: You can develop your own components on this basis. We can use Sockets. We can develop shortcomings for network programming: more program volume, the code to send mail is as follows: DIM Senddata As String Dim Szdata As Byte () DIM CRLF AS STRING CRLF = "/ R / N" Creates a connection with the server 25 port DIM SMTPSERV AS New TcpClient (TXTSMTP.TEXT, 25) Lstlog.Items.clear () display initial information server 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 ()) '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:" "<" txttttt "> crlf szdata = system.text.Encoding.ascii.getbytes (Senddata.tochararray ()) NetStrm.Write (SZDATA, 0, SZDATA.LENGTH) LSTLOG.ITEMS.ADD (RDStrm.Readline ()) 'Preparing for 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 theme Senddata = "Subject:" txtsub.Text CRLF 'transmits content sendData = sendData txtmsg.Text CRLF' end of the transmission 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 connection netstrm.close () RDStrm.close () Lstlog.Items.Add ("Connection Off") Lstlog.Items. Add ("Send Success") You can also refer to: Creating a Mail Send Component (SMTP) http://www.aspcool.com/lanmu/browse1.asp?id=968

& bbsuser = CSHARP 4, IIS SMTP comes with basic lettering component cdonts You don't have to download, Microsoft has provided this component, as long as 2000, NT's SMTP will have. Advantages: Components comes from the operating system: 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 = ***' letter to send mymail.subject = *** 'letter theme mymail.body = ***' Letter text 'Setting priority, 0- Not important, 1-general, 2- important. MyMail.Importance = 2 mymail = nothing 5, using Jmail Component Jmail has the following features: (1) You can send attachments; (2) Detailed logging ability, easy to view the problem; (3) Setting up mail Priority; (4) Support for multiple format emails, such as sending emails in HTML or TXT. 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

转载请注明原文地址:https://www.9cbs.com/read-127398.html

New Post(0)