This article describes the. NET environment, and the advantages and disadvantages of five different mail delivery solutions. Choose what program, depending on the application and requirements of the program, this article gives a few examples of programs for your reference.
1. Send with Outlook
For example: I have seen the Ufida U8 manufacturing (demo), where the mail function is by calling the Outlook ActiveX components
Advantages: Simple Development
Disadvantage: Dependent on Outlook components, SMTP Mail Service
The code to send the message is as follows:
The following is a reference fragment:
Private Sub Send ()
Dim Outobjas 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
2. Web development, referencing System.Web.Mail classes in asp.net
The System.Web.Mail namespace contains classes that enable you to construct and send messages using the CDOSYS (Windows 2000 Collaboration Data object) message component. Mail messages are delivered by means of an SMTP mail service or any SMTP server built into Microsoft Windows 2000. Classes in this namespace can be in asp.net or any managed application
MailAttachment provides properties and methods for constructing e-mail attachments.
MailMessage provides properties and methods for constructing e-mail messages.
SmtpMail provides properties and methods for sending messages using the Collaboration Data Object (CDOSYS) message component of Windows 2000.
Messages can be delivered through the SMTP mail service or any SMTP server that is built into Microsoft Windows 2000. Types in the System.Web.Mail namespace can be used in asp.net or in any managed application.
SMTP server settings, now some free mail providers are no longer providing SMTP service for all messages, when sending mail, need to authenticate user information, consider SMTP user authentication issues
If the SMTP server on the local computer, send fast, basically do not worry, if not the local server, then it is best not to send too much, one is the speed problem, the second is to send too many messages, the SMTP server may be considered spam and denial of service
The code is as follows:
The following is a reference fragment:
Private Sub button1_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button1.Click
Dim Mailobjas New MailMessage ()
Dim Smtpas SmtpMail
' Define the name of the SMTP server
Smtp. SmtpServer = "SMTP. XXX.com "
' Define the sending address of the message
Mailobj.from = "Lihonggen@XXX.com"
' Define the receiving address of the message
mailobj.to = "AAA@XXX.com"
"Defines the message's dark-sent address
MAILOBJ.BCC = "Aa@sina.com"
' Define the CC address of the message
mailobj.cc = "Aaa@sina.com"