当前位置:网站首页>C # use smtpclient The sendasync method fails to send mail, and always returns canceled
C # use smtpclient The sendasync method fails to send mail, and always returns canceled
2022-07-04 09:34:00 【Dandelion_ drq】
problem :
call SmtpClient.SendAsync, stay SendCompleted The callback function of always gets e.Cancelled by true.
And then I tested it , Same code , Just put SmtpClient.SendAsync Change to SmtpClient.Send Method , Mail sent successfully .
reason :
Send... Before sending email SmtpClient The instance of is released . because SendAsync Is an asynchronous operation , After calling this method, you just push the email to SMTP The server , The sending operation has not been completed yet , When SmtpClient When the instance is released , It cancels any outstanding asynchronous operations , So this email was also cancelled . therefore , The right thing to do is to put SmtpClient The instance of is placed in SendCompleted And then release ,MailMessage Examples are the same , Otherwise it will be reported
System.Net.Mail.SmtpException: Failed to send email . —> System.ObjectDisposedException: The released object cannot be accessed .
Error of .
Reference resources :
边栏推荐
- 保姆级JDEC增删改查练习
- C language - Introduction - Foundation - syntax - [variable, constant light, scope] (V)
- Research Report on research and investment prospects of China's testing machine industry (2022 Edition)
- In depth research and investment strategy report on China's hydraulic parts industry (2022 Edition)
- Analysis report on the production and marketing demand and investment forecast of tellurium dioxide in the world and China Ⓣ 2022 ~ 2027
- 《网络是怎么样连接的》读书笔记 - 认识网络基础概念(一)
- How to ensure the uniqueness of ID in distributed environment
- Multilingual Wikipedia website source code development part II
- AMLOGIC gsensor debugging
- "How to connect the Internet" reading notes - FTTH
猜你喜欢

2022-2028 global gasket plate heat exchanger industry research and trend analysis report

LeetCode 74. Search 2D matrix

You can see the employment prospects of PMP project management

How do microservices aggregate API documents? This wave of show~

【LeetCode 42】501. Mode in binary search tree
![C language - Introduction - Foundation - syntax - [variable, constant light, scope] (V)](/img/dc/5c8077c10cdc7ad6e6f92dedfbe797.png)
C language - Introduction - Foundation - syntax - [variable, constant light, scope] (V)

At the age of 30, I changed to Hongmeng with a high salary because I did these three things

2022-2028 global seeder industry research and trend analysis report

26. Delete duplicates in the ordered array (fast and slow pointer de duplication)

Solve the problem of "Chinese garbled MySQL fields"
随机推荐
2022-2028 global seeder industry research and trend analysis report
Solution to null JSON after serialization in golang
UML sequence diagram [easy to understand]
Lauchpad X | 模式
Reading notes on how to connect the network - hubs, routers and routers (III)
Launpad | 基础知识
2022-2028 research and trend analysis report on the global edible essence industry
什么是权限?什么是角色?什么是用户?
Launpad | Basics
Report on the development trend and prospect trend of high purity zinc antimonide market in the world and China Ⓕ 2022 ~ 2027
Development trend and market demand analysis report of high purity tin chloride in the world and China Ⓔ 2022 ~ 2027
mmclassification 标注文件生成
Global and Chinese markets of hemoglobin analyzers in care points 2022-2028: Research Report on technology, participants, trends, market size and share
Launpad | basic knowledge
HMS core helps baby bus show high-quality children's digital content to global developers
How does idea withdraw code from remote push
Clion console output Chinese garbled code
Leetcode (Sword finger offer) - 35 Replication of complex linked list
Report on research and investment prospect prediction of China's electronic grade sulfuric acid industry (2022 Edition)
"How to connect the network" reading notes - Web server request and response (4)