Send Email From C# / VB.NET / ASP.NET Using SMTP - GemBox
Có thể bạn quan tâm
The following example shows how you can use the GemBox.Email library to send an email with a plain text body from your console application using C# or VB.NET code.
- C#
- VB.NET
The above code creates a simple email that is represented with a MailMessage object.It has a plain text body, and it's sent using the SmtpClient to multiple recipients, which can be specified in MailMessage.To, MailMessage.Cc and MailMessage.Bcc address collections.
The SmtpClient.SendMessage method sends the MailMessage to the SMTP server for delivery, and the SMTP server will immediately send that email to its recipients.
If you'd like to know how to create advanced emails, including HTML body, attachment, and images, check the HTML with Attachment example.
You can reuse the same instance of SmtpClient to send multiple emails.
However, in the case of an ASP.NET application, we encourage you to recreate the client for each request, as shown in the following examples.
The SmtpClient.SendMessage method sends the MailMessage to the SMTP server for delivery, and the SMTP server will immediately send that email to its recipients.
If you'd like to know how you can create advance emails, which include HTML body, attachment and images, then check the HTML with Attachment example.
Sending email in ASP.NET MVC
With this example, you can incorporate email-sending capabilities into ASP.NET MVC applications.
- C#
- VB.NET
Embedded within the ExampleController class, the SendEmail action method demonstrates connecting to an SMTP server, setting up security parameters, and sending an email message.
Sending email in ASP.NET Web Forms
This example demonstrates a method for integrating email functionality into ASP.NET Web Forms applications using the GemBox.Email library.
- C#
- VB.NET
The code, embedded within the ExamplePage class, handles a secure connection to an SMTP server, authenticating credentials and sending an email message upon button click (SendEmailButton_Click). You can easily adapt and customize this code to suit your specific needs, making it a practical resource for incorporating essential email-sending capabilities in ASP.NET Web Forms projects.
Using an SMTP Server Like Gmail, Outlook and Yahoo
Every SMTP server has a different server address, and you'll need to find out what your email server's address is before you can use it from your C# and VB.NET code.
To connect an SMTP server with your .NET application, you need to create the SmtpClient object and provide it with the address of your outgoing mail server.
There are many free email providers that you can use to send an email. Here is the summary of SMTP server settings for some commonly used free email services:
Provider | Host | Port | ConnectionSecurity |
---|---|---|---|
Gmail | smtp.gmail.com | 465 | SSL |
Outlook | smtp-mail.outlook.com | 587 | STARTTLS |
Office 365 | smtp.office365.com | 587 | STARTTLS |
Yahoo | smtp.mail.yahoo.com | 465 | SSL |
AOL | smtp.aol.com | 465 | SSL |
Từ khóa » Visual Basic Send Email
-
Sending Email From Visual Basic - Stack Overflow
-
VB.Net - Send Email - Tutorialspoint
-
How To Send Email In Visual Basic VB.NET - Codebun
-
How To Send Emails Using VB.NET - YouTube
-
How To: Programmatically Send Email - Visual Studio (Windows)
-
Sending Email Using VBnet And Smtp. - Microsoft Q&A
-
Send Email In VB.NET - Tutorial - AdminSystem Software Limited
-
Send Email In VB 6.0 - Example Codes
-
VBA Send Email From Excel - WallStreetMojo
-
How To Send Email Using VB.Net - The Crazy Programmer
-
Sending EMails With Visual Basic With LinkedResources ... - CodeGuru
-
Visual Basic Script To Send Email - Oracle Help Center
-
What Is SMTP - Net
-
Send An Email With Outlook Using VB .Net - Visual Basic .NET - Bytes