Five different email sending solutions in the. NET Environment

Source: Internet
Author: User
Tags mailmessage

This article describes five different email sending solutions in the. NET environment, as well as their advantages and disadvantages. Which scheme is selected depends on the purpose and needs of the program? Several schemes are provided in this article for your reference.

1. Use the mail provided by outLook
For example, I have met U8 production and manufacturing (demo version). The mail function is to call the ActiveX component of outLook.
Advantage: simple development
Disadvantages: relying on outlook components, SMTP mail service
The code for sending an email is as follows:
The following is a reference clip:
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: reference the System. Web. Mail class in ASP. Net.

The System. Web. Mail namespace contains a class that allows you to construct and send messages using the CDOSYS (collaborative data object for Windows 2000) Message component. Mail messages are sent through the SMTP mail service built in Microsoft Windows 2000 or any SMTP server. Classes in this namespace can be stored in ASP. Net or any Managed Application
MailAttachment provides attributes and methods for constructing email attachments.
MailMessage provides the attributes and methods used to construct an email.
SmtpMail provides the attributes and methods used to send messages using the collaborative data object (CDOSYS) Message component of Windows 2000.
Emails can be sent through the built-in SMTP mail service in Microsoft Windows 2000 or any SMTP server. The types in the System. Web. Mail namespace can be used in ASP. Net or any hosting application.
For Smtp server settings, some free mail providers no longer provide Smtp services for all emails. When sending emails, you need to verify the user information and consider Smtp User authentication issues.
If the Smtp server is on a local computer, the sending speed is very fast and you don't have to worry about it. If it's not a local server, it's best not to use this too much for sending. First, it's a speed problem, the second is to send too many emails, and the Smtp server may consider it as spam and refuse services.
The Code is as follows:
The following is a reference clip:
Private Sub button#click (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles Button1.Click
Dim mailObjAs New MailMessage ()
Dim smtpAs SmtpMail

''Defines the SMTP server name
Smtp. SmtpServer = "smtp.XXX.com"

''Defines the mail sending Address
MailObj. From = "lihonggen@XXX.com"

''Defines the email Receiving address

MailObj. To = "AAA@XXX.com"
''Defines the mail's dark sending Address

MailObj. Bcc = "aa@sina.com"

''Defines the CC address of the email
MailObj. Cc = "aaa@sina.com"

<

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.