当前位置:网站首页>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 :
边栏推荐
- Get the source code in the mask with the help of shims
- Simulate EF dbcontext with MOQ - mocking EF dbcontext with MOQ
- Global and Chinese market of air fryer 2022-2028: Research Report on technology, participants, trends, market size and share
- Report on investment analysis and prospect trend prediction of China's MOCVD industry Ⓤ 2022 ~ 2028
- Daughter love in lunch box
- Launpad | basic knowledge
- Tkinter Huarong Road 4x4 tutorial II
- "How to connect the Internet" reading notes - FTTH
- 2022-2028 global industry research and trend analysis report on anterior segment and fundus OTC detectors
- Analysis report on the production and marketing demand and investment forecast of tellurium dioxide in the world and China Ⓣ 2022 ~ 2027
猜你喜欢
C language - Introduction - Foundation - syntax - [operators, type conversion] (6)
C language - Introduction - Foundation - syntax - [main function, header file] (II)
Langage C - démarrer - base - syntaxe - [opérateur, conversion de type] (vi)
How to batch change file extensions in win10
C语言-入门-基础-语法-数据类型(四)
HMS core helps baby bus show high-quality children's digital content to global developers
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
pcl::fromROSMsg报警告Failed to find match for field ‘intensity‘.
After unplugging the network cable, does the original TCP connection still exist?
How to ensure the uniqueness of ID in distributed environment
随机推荐
2022-2028 global probiotics industry research and trend analysis report
How should PMP learning ideas be realized?
2022-2028 global tensile strain sensor industry research and trend analysis report
C语言-入门-基础-语法-[运算符,类型转换](六)
Langage C - démarrer - base - syntaxe - [opérateur, conversion de type] (vi)
LeetCode 74. Search 2D matrix
After unplugging the network cable, does the original TCP connection still exist?
Pueue data migration from '0.4.0' to '0.5.0' versions
How to write unit test cases
Fatal error in golang: concurrent map writes
DR6018-CP01-wifi6-Qualcomm-IPQ6010-IPQ6018-FAMILY-2T2R-2.5G-ETH-port-CP01-802-11AX-MU-MIMO-OFDMA
26. Delete duplicates in the ordered array (fast and slow pointer de duplication)
《网络是怎么样连接的》读书笔记 - 认识网络基础概念(一)
Write a jison parser from scratch (6/10): parse, not define syntax
Lauchpad X | 模式
2022-2028 global special starch industry research and trend analysis report
《网络是怎么样连接的》读书笔记 - FTTH
After unplugging the network cable, does the original TCP connection still exist?
2022-2028 global strain gauge pressure sensor industry research and trend analysis report
《网络是怎么样连接的》读书笔记 - WEB服务端请求和响应(四)