How does .net send emails?
Document Directory
Introduction
IEmailSender
ISmtpEmailSender
NullEmailSender
Configuration
Integrated MailKit
Installation
Integration
Usage
- ## Customization
##Introduction
Sending emails is a very common task that is required by almost every application. Abp provides a basic framework for simply sending emails and separates out the configuration of the email service for it.
IEmailSender
It is a service that you can simply use to send emails without knowing its details. The usage is as follows:
public class TaskManager : IDomainService {private readonly IEmailSender _emailSender; public TaskManager(IEmailSender emailSender) { _emailSender = emailSender; }public void Assign(Task task, Person person) {//Assign task to the persontask.AssignedTo = person;//Send a notification email _emailSender.Send( to: person.EmailAddress, subject: "You have a new task!", body: $"A new task is assigned for you: <b>{task.Title}</b>", isBodyHtml: true);} }
ISmtpEmailSender
There is also an ISmtpEmailSender, which extends IEmailSender and adds the BuildClient method to create a SmtpClient, and then you can use SmtpClient directly (in .net core It cannot be used because .net core does not contain SmtpClient and MailMessage). In most cases it is sufficient to use ISmtpEmailSender.
NullEmailSender
NullEmailSender is the implementation of the Null object design pattern of IEmailSender and can be used in unit testing and property dependency injection.
Configuration
Email sending uses the settings management system to read the configuration of email sending. The names of all settings are defined in Abp.Net.Mail in the form of constants. In the .EmailSettingNames class. The following are its values and descriptions:
- Abp.Net.Mail.
- DefaultFromAddress
: The default email sender's address (as in the example above).
Abp.Net.Mail. - DefaultFromDisplayName
: The default email sender display name (as in the example above).
Abp.Net.Mail. - Smtp.Host
: IP or domain name of the SMTP server (default is 127.0.0.1).
Abp.Net.Mail. - Smtp.Port
: The port of the SMTP server (default is 25).
Abp.Net.Mail. - Smtp.UserName
: The user name that needs to be provided when the SMTP server requires authentication.
Abp.Net.Mail. - Smtp.Password
: The password that needs to be provided when the SMTP server requires authentication.
Abp.Net.Mail. - Smtp.Domain
: The domain name that needs to be provided when the SMTP server requires authentication.
Abp.Net.Mail. - Smtp.EnableSsl
: Indicates whether (true) or not (false) an SMTP server requires the use of SSL connections (default is false).
Abp.Net.Mail. - Smtp.UseDefaultCredentials
: When True, use the default credentials instead of the provided user and password (default is true).
Integrated MailKit
Since .net core does not support the standard System.Net.Mail.SmtpClient, we need a third-party supplier to To send emails, fortunately, MailKit is a good alternative to the default Smtpclient, and Microsoft recommends using it.
Abp.MailKit package is elegantly integrated into Abp's mail sending system, so you can still use IEmailSender through MailKit as before.
Installation
First, install the Abp.MailKit package into your project:
Install-Package Abp.MailKit
Integration
Add AbpMailKitModule dependency to your module:
[DependsOn(typeof(AbpMailKitModule))]public class MyProjectModule : AbpModule {//...}
Usage
You can use IEmailSender as described previously , because the Abp.MailKit package registers the MailKit implementation for it. Also uses the configuration defined above.
Customization
When creating MailKit's SmtpClient, you may have additional configuration or your own customization. At this time, you can replace IMailKitSmtpBuilder with your own implementation The registration of the interface can be made simpler by inheriting DefaultMailKitSmtpBuilder. For example, you want to provide a credential for all SSL connections. In this case, you can override the ConfigureClient method as follows:
public class MyMailKitSmtpBuilder : DefaultMailKitSmtpBuilder{public MyMailKitSmtpBuilder(ISmtpEmailSenderConfiguration smtpEmailSenderConfiguration) : base(smtpEmailSenderConfiguration) { }protected override void ConfigureClient(SmtpClient client) {client.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true; base.ConfigureClient(client); } }
[DependsOn(typeof(AbpMailKitModule))]public class MyProjectModule : AbpModule {public override void PreInitialize() { Configuration.ReplaceService<IMailKitSmtpBuilder, MyMailKitSmtpBuilder>();}//...}
The above is the detailed content of How does .net send emails?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Is the Outlook mail icon missing from Windows 11's Control Panel? This unexpected situation has caused confusion and concern among some individuals who rely on OutlookMail for their communication needs. Why don't my Outlook emails show up in Control Panel? There may be several possible reasons why there are no Outlook mail icons in Control Panel: Outlook is not installed correctly. Installing Office applications from the Microsoft Store does not add the Mail applet to Control Panel. The location of the mlcfg32.cpl file in Control Panel is missing. The path to the mlcfg32.cpl file in the registry is incorrect. The operating system is not currently configured to run this application

We've been talking lately about the many features Microsoft plans to add to its latest operating system, Windows 11. But don't think that Microsoft will add nothing and take nothing back. In fact, the software giant started removing quite a few old features. After announcing plans to decommission MSDT functionality ahead of the release of Windows 12, a Redmond developer has more bad news. We are actually talking about remote mail slot legacy tool. Trust us when we say you actually want to know this. Microsoft has started deprecating this feature in build 25314. We are sure you remember that just a few days ago, Microsoft released build 25314 in its new canary channel. The above version contains many new features

If you find that blank pages appear when printing a mail merge document using Word, this article will help you. Mail merge is a convenient feature that allows you to easily create personalized documents and send them to multiple recipients. In Microsoft Word, the mail merge feature is highly regarded because it helps users save time manually copying the same content for each recipient. In order to print the mail merge document, you can go to the Mailings tab. But some Word users have reported that when trying to print a mail merge document, the printer prints a blank page or doesn't print at all. This may be due to incorrect formatting or printer settings. Try checking the document and printer settings and make sure to preview the document before printing to ensure the content is correct. if

PHP sends emails asynchronously: avoid long waits for emails to be sent. Introduction: In web development, sending emails is one of the common functions. However, since sending emails requires communication with the server, it often causes users to wait for a long time while waiting for the email to be sent. In order to solve this problem, we can use PHP to send emails asynchronously to optimize the user experience. This article will introduce how to implement PHP to send emails asynchronously through specific code examples and avoid long waits. 1. Understanding sending emails asynchronously

On Douyin, users can not only share their life details and talents, but also interact with other users. In this process, sometimes we need to send files to other users, such as pictures, videos, etc. So, how to send files to others on Douyin? 1. How to send files to others on Douyin? 1. Open Douyin and enter the chat interface where you want to send files. 2. Click the "+" sign in the chat interface and select "File". 3. In the file options, you can choose to send pictures, videos, audio and other files. After selecting the file you want to send, click "Send". 4. Wait for the other party to accept your file. Once the other party accepts it, the file will be transferred successfully. 2. How to delete files sent to others on Douyin? 1. Open Douyin and enter the text you sent.

Recently, many users have reported the issue of Outlook emails getting stuck in the outbox. Even after several attempts to send the email, the issue was not resolved. When you see this issue and check your outbox folder, the message will be stuck there. Possible reasons for emails getting stuck in Outlook outbox: The attachments in the email exceed the size limit, which slows down the sending process. Outlook account authentication issues with mail server Incorrect send/receive settings in Outlook or mail server offline Outlook. Outlook data files are being used by some other software. Antivirus software scans outgoing emails. If this problem has been bothering you and you are unable to send an email

WhatsApp has launched a new option that allows users to send photos and videos in high resolution through the messaging platform. Read on to find out how it's done. WhatsApp has released an update that allows iPhone and Android users to send photos and videos in high resolution, finally addressing the service's low-quality media sharing limitations. The option is called "HD Quality" and means users can send clearer photos and videos with minimal compression. For example, images captured on the iPhone can now be sent at 3024x4032 resolution instead of the previous maximum of 920x1280, while videos can be sent at 1280×718 resolution instead of 848×476.

PHP email tracking function: understand user behavior and feedback on emails In modern society, email has become an indispensable part of people's daily life and work. For businesses, sending emails is one of the important ways to communicate with customers and promote products or services. However, after an email is sent, how do we know whether it was received, read, or how the user reacted to the content of the email? At this time, the email tracking function becomes particularly important. The email tracking function can help us understand user behavior and feedback on emails
