当前位置:网站首页>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 :
边栏推荐
- 2022-2028 global visual quality analyzer industry research and trend analysis report
- Clion console output Chinese garbled code
- Write a jison parser from scratch (5/10): a brief introduction to the working principle of jison parser syntax
- At the age of 30, I changed to Hongmeng with a high salary because I did these three things
- Launpad | 基礎知識
- Sword finger offer 30 contains the stack of Min function
- Langage C - démarrer - base - syntaxe - [opérateur, conversion de type] (vi)
- Global and Chinese markets of hemoglobin analyzers in care points 2022-2028: Research Report on technology, participants, trends, market size and share
- 2022-2028 global intelligent interactive tablet industry research and trend analysis report
- Trees and graphs (traversal)
猜你喜欢
Clion console output Chinese garbled code
HMS core helps baby bus show high-quality children's digital content to global developers
2022-2028 global intelligent interactive tablet industry research and trend analysis report
Leetcode (Sword finger offer) - 35 Replication of complex linked list
2022-2028 research and trend analysis report on the global edible essence industry
AMLOGIC gsensor debugging
PHP is used to add, modify and delete movie information, which is divided into foreground management and background management. Foreground users can browse information and post messages, and backgroun
Markdown syntax
Web端自动化测试失败原因汇总
2022-2028 global seeder industry research and trend analysis report
随机推荐
[on February 11, 2022, the latest and most fully available script library collection of the whole network, a total of 23]
QTreeView+自定义Model实现示例
Web端自动化测试失败原因汇总
How does idea withdraw code from remote push
About the for range traversal operation in channel in golang
Multilingual Wikipedia website source code development part II
Dynamic analysis and development prospect prediction report of high purity manganese dioxide in the world and China Ⓡ 2022 ~ 2027
Daughter love: frequency spectrum analysis of a piece of music
Ultimate bug finding method - two points
Research Report on the development trend and Prospect of global and Chinese zinc antimonide market Ⓚ 2022 ~ 2027
Analysis report on the development status and investment planning of China's modular power supply industry Ⓠ 2022 ~ 2028
PHP book borrowing management system, with complete functions, supports user foreground management and background management, and supports the latest version of PHP 7 x. Database mysql
Deadlock in channel
Solution to null JSON after serialization in golang
Launpad | basic knowledge
2022-2028 global protein confectionery industry research and trend analysis report
保姆级JDEC增删改查练习
UML 时序图[通俗易懂]
The 14th five year plan and investment risk analysis report of China's hydrogen fluoride industry 2022 ~ 2028
What is permission? What is a role? What are users?