当前位置:网站首页>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 :
边栏推荐
- Global and Chinese market of sampler 2022-2028: Research Report on technology, participants, trends, market size and share
- In depth investigation and Strategic Research Report on China's motion controller Market (2022 Edition)
- UML 时序图[通俗易懂]
- Golang defer
- Get the source code in the mask with the help of shims
- 什么是权限?什么是角色?什么是用户?
- Clion console output Chinese garbled code
- 2022-2028 global protein confectionery industry research and trend analysis report
- el-table单选并隐藏全选框
- 2022-2028 global intelligent interactive tablet industry research and trend analysis report
猜你喜欢

HMS core helps baby bus show high-quality children's digital content to global developers

AMLOGIC gsensor debugging

Svg image quoted from CodeChina

Opencv environment construction (I)

C language - Introduction - Foundation - syntax - data type (4)

After unplugging the network cable, does the original TCP connection still exist?

Nurse level JDEC addition, deletion, modification and inspection exercise

26. Delete duplicates in the ordered array (fast and slow pointer de duplication)
](/img/3f/4d8f4c77d9fde5dd3f53ef890ecfa8.png)
C語言-入門-基礎-語法-[運算符,類型轉換](六)

If you can quickly generate a dictionary from two lists
随机推荐
pcl::fromROSMsg报警告Failed to find match for field ‘intensity‘.
Nurse level JDEC addition, deletion, modification and inspection exercise
Are there any principal guaranteed financial products in 2022?
Write a jison parser from scratch (6/10): parse, not define syntax
lolcat
Trees and graphs (traversal)
Explain TCP protocol in detail three handshakes and four waves
Launpad | 基礎知識
什么是权限?什么是角色?什么是用户?
In depth research and investment strategy report on China's hydraulic parts industry (2022 Edition)
Launpad | basic knowledge
After unplugging the network cable, does the original TCP connection still exist?
About the for range traversal operation in channel in golang
How to display √ 2 on the command line terminal ̅? This is actually a blog's Unicode test article
Tkinter Huarong Road 4x4 tutorial II
At the age of 30, I changed to Hongmeng with a high salary because I did these three things
Trim leading or trailing characters from strings- Trim leading or trailing characters from a string?
Target detection -- intensive reading of yolov3 paper
2022-2028 global special starch industry research and trend analysis report
C語言-入門-基礎-語法-[運算符,類型轉換](六)