¤W¤@½g¥DÃD :: ¤U¤@½g¥DÃD |
µoªí¤H |
¤º®e |
iswith
µù¥U®É¶¡: 2022-11-04 ¤å³¹: 92
²Ä 1 ¼Ó
|
µoªí©ó: ¬P´Á¤ ¤T¤ë 07, 2025 9:50 am ¤å³¹¥DÃD: mailkit v1.0 ^¤åª© |
|
|
±µ¤f对±µºÃ问¡G
1.«çý©获¨úMailKit ±Â权¡H
MailKit ¬O开·½库¡Aªö¥Î MIT 许¥i证¡AÆÓ»Ý额¥~±Â权§Y¥i§K费¨Ï¥Î©Ò¦³¥\¯à¡]¥]¬A SMTP¡BPOP3¡BIMAP¡BIDLE ¼Ò块¡^¡C
Y»Ý专MailKitVFP²¾Èª©¤ä«ù¡A¥i联¨t¡G
WX¡GZ68256904
Email¡Giswithzhz@outlook.com
MailKit¤À两类¡G1.STMP¡BPOP3¼Ò块 ±Â权
2.STMP¡BPOP3¼Ò块¡BIMAP¡BIDLE ¼Ò块±Â权
2.STMP发°e邮¥ó¨Ï¥Î¦P¨B还¬OÉݨB发°e¡H
±À¯òÉݨB发°e¡G¨Ï¥Î SendEmailAsync¤èªkÁ×§Kªý¶ë¥D线µ{¡A´£¤É应¥Î响应³t«×¡C
¦P¨B¯S®í±¡úG¤U¨Ï¥Î¡C
3.VFP¬O单线µ{µ{§Ç¡A¦pªG¨Ï¥ÎÉݨB发°e¡A§ÚªºVFP当«e线µ{¦pªG执¦æ¤@个¯Ó时较长ªº应¥Î¡G¦pSPT¬d询¡A会¦¸会©µ迟SendEmailAsync发°e吗¡H
¤£会
验证逻辑ªº¨B骤说©ú¤Î¥Ü¨Ò
¥H¤U¬O¤À¨B验证 SendEmailAsync ¦bVFP¥D线µ{ªý¶ë时¤´¯àÉݨB发°e邮¥ó ªº¤èªk¡G
1. ®Ö¤ß逻辑验证¥Ø标
ÚÌ认ÉݨB发°e¤£¨Ì赖VFP¥D线µ{¡G§Y¨ÏVFP¥D线µ{³Qªý¶ë¡]¦p执¦æSleep(20¤À钟)¡^¡A邮¥ó发°e应¯à¦b¦Z¥x独¥ß§¹¦¨¡C
验证¨Æ¥ó³qª¾ªº队¦CÉó¨î¡G发°e§¹¦¨¦Zªº¦^调«H®§会¦b¥D线µ{«ìÎ`¦Z显¥Ü¡A¦Ó«D³Q丢弃¡C
2. ¥Ü¨Ò¥N码实现
¥H¤U为§¹¾ãªºVFP¥Ü¨Ò¥N码¡A¼ÒúQÉݨB发°e邮¥ó¦Zªý¶ë¥D线µ{ªº场´º¡G
* 1. ©wúåWin32APIªºSleep¨ç数
->DECLARE INTEGER Sleep IN Win32API INTEGER nMilliseconds
->执¦æ mailkit_how stmp add attachments async sending email.prg &&该DEMO¬O执¦æ¤@个ªþ¥ó发°e¡A§A¥i¥HÓì当²K¥[¤@个20MB¥ª¥kªºªþ¥ó执¦æ¡C
* 2. ¥ß§Yªý¶ëVFP¥D线µ{20¤À钟
->Sleep(1000 * 60 * 20) && 20¤À钟
邮¥ó¦b20¤À钟内¨ì达¦¬¥ó½cYÉݨB发°e逻辑¥¿ÚÌ¡Aªþ¥ó¤W传©MSMTP³q«H将¦b¦Z¥x线µ{§¹¦¨¡AÆÓ»Ýµ¥«Ý¥D线µ{«ìÎ`¡C
检¬d¤è¦¡¡G¦bVFP¥D线µ{¥ð¯v´Á间¡Aµn录邮½c¬d¬Ý¬O§_¦¬¨ì邮¥ó¡C¨Æ¥ó¦^调¦bVFP¥D线µ{«ìÎ`¦Z执¦æ 发°e§¹¦¨¨Æ¥ó OnStmpSendEmailAsync 会³QVFPªº®ø®§队¦C暂¦s¡A«Ý¥D线µ{«ìÎ`¦ZàD发¡C
4.STMP发°e邮¥ó¨Ï¥ÎÉݨB发°e¡A¦p¦óª¾¹D¬Y¦¸发°eªº邮¥ó¬O§_¦¨¥\¡H
¨Ì赖 MessageId °l踪状态¡G
创«Ø邮¥ó时¥Í¦¨°ß¤@ MessageId¡G发°e¦¨¥\§¹¦¨¦Z¥Ñ¡§OnStmpSendEmailAsync¡¨获¨ú«H®§¡A
¨äªð¦^参数¡GiMimeMessage结ÌÛ类¤¤¦s¦b¬Û¦PªºMessageId¡A§Y¬Y¦¸发°e邮¥ó¦¨¥\¡C
参¦Ò逻辑¡G
->创«Ø发¥ó¯ó½Z记录"iMimeMessage.MessageId"
->³q过¡§SendEmailAsync¡¨ÉݨB发°e¡A标识记录¡§发°e¡¨
->当¡§OnStmpSendEmailAsync¡¨¨Æ¥óàD发时 ³q过iMimeMessage.MessageId«·s检¯Á¯ó½Z记录¡A¦}标识¡§¤w发°e¡¨©Î¡§发°e¥¢败¡¨
->当¥Î户°h¥X时检测¬O§_¦³¡§发°e¡¨¯ó½Z记录"iMimeMessage.MessageId"时¥¼检测¨ì¡§¤w发°e¡¨标识´£¿ô«È户¬O§_°h¥X¡A邮¥ó将°±¤î发°e¡C
¯ó½Z状态ºÞ²z¡G结¦X数Õu库©Î¥»¦a缓¦s记录发°e状态¡C
¥i参¦ÒDEMO¡G
mailkit_how stmp send email async.prg
5.STMP发°e邮¥ó¤ä«ù¦h个¦¬¥ó¤H吗¡H
¤ä«ù¡Gª½±µ¦b To¡BCc¡BBcc ¤¤²K¥[¦h个¦a§}
6.STMP发°e邮¥ó¤ä«ù¦h个ªþ¥ó吗¡H
¤ä«ù¡A³q过 AddAttachment ²K¥[¦h个ªþ¥ó¡Gm.lcContentId =.AddAttachment( "NetMailKit.dll" , @lcErrorMsg )
ª`·N邮¥ó®e¶q¤j¤p¨C®a账户¨äªA务¾¹处²z¬O¤£¤@ý©ªº¡C这点«Ü«n¡C
¤£¦Pªº邮¥óªA务´£¨Ñ°Ó¡]¦pGmail¡BOutlook¡B¥ø业¦Û«ØªA务¾¹¡^对邮¥ó¤j¤p¥i¯à¦³¤£¦Pªº¨î¡C
³q±`¡A这个¨î¥i¯à¦b10MB¨ì50MB¤§间¡A¦ý¨ãÊ^»Ýn¬d¬Ý¦U®aªº¤å档©ÎªA务条´Ú¡C
¦pªG邮¥ó¶W过ªA务¾¹¤¹许ªº¤j¤p¡A发°e会³Q©Ú绝¡A©ÎªÌ¦¬¥ó¤è¥i¯àÆÓªk±µ¦¬¡C
¥i参¦ÒDEMO¡G
mailkit_how stmp add attachments async sending email.prg
7.STMP发°e邮¥ó¤ä«ù§Û°e¡A±K°e,¦^Î` 吗¡H
¤ä«ù
¥i参¦ÒDEMO¡G
mailkit_how stmp add cc.bcc.replyto in sending email.prg
8.POP3¬O¼W¶q¦¬¥ó还¬O¥þ¶q¦¬¥ó
Àq认¬O¡§¥þ¶q¦¬¥ó¡¨¡A虽µM¥i¥H³q过 UIDL ¥i实现¼W¶q,¦ý¼W¶q¦¬¥óªº¥i¾a©Ê¨Ì赖ªA务¾¹ UID 稳©w©Ê¡A
¬Y¨Ç邮¥óªA务¾¹¤£会«O¯d¦h长时间¡A¤ñ¦pQQ¥u¦³30¤Ñ¡A©Ò¥H¦Z´Á¤]¤£会对该¼Ò块¦³«Ü¤jªº¤É级¡A
逻辑¤W¥i¥HPOP3¥þ¶q¦¬¥ó¦Z删°£ªA务¾¹邮¥ó¡A¦ý²¾动ºÝ¥i¯àÆÓªk¬d¬Ý¤F¡C
9.IDLE ¥i¥H¤ä«ù¦h个账户¦Û动¦¬¥ó吗¡H
¤ä«ù¡A²z论¥i¥H实¨Ò¤ÆÆÓ账户ªºIDLE¡A¨C个账户独¥ß实¨Ò¤Æ ImapClient ¦}ûD动 IDLE 监§v¡G
DEMO¥u¦³¤T个¤À别为¡GoMailKit_IMAP_LELD ¡BoMailKit_IMAP_LELDa¡BoMailKit_IMAP_LELDb
¥i参¦ÒDEMO¡G
mailkit_how iamp startidle.prg
mailkit_how iamp startidle(another account a).prg
mailkit_how iamp startidle(another account b).prg
资·½ºÞ²z¡G¦h账户»Ýª`·N线µ{©MÊI络连±µ开销¡C
10.IMAP¤ä«ù将¬Y个邮¥ó¤U载为¥»¦a¤å¥ó吗¡H
¤ä«ù¡A¤èªk¡§DownloadMessagesById()¡¨
¡§DownloadMessageStreamsById()¡¨ ¬y¦¡处²z¤j邮¥ó
¥i¥H®ÚÕuID将邮¥ó¤U载为¥»¦aeml¤å¥ó«O¦s¡A¥Ñ¤èªk¡§MailKit.LoadLocalEml()¡¨¸ÑªR为¡§iMimeMessage¡¨类结ÌÛ读¨ú«H®§¡C
¥i参¦ÒDEMO¡G
mailkit_how iamp sync and download messages by uniqueid to local eml files.prg
mailkit_how iamp sync and download messages by uniqueid to imimemessage.prg
mailkit_how to parse local eml files.prg
11.ªì¦¸ûD¥ÎIDLE¬O¤£¬O¡§¥þ¶q¦¬¥ó¡¨¡A¦p¦ó¼W¶q¦¬¥ó¡H
¦bªì¦¸¨Ï¥ÎIDLE¼Ò¦¡¬O¡§¥þ¶q¦¬ºKn¥ó¡¨¡I
¼W¶q¦¬¥ó¡G»Ýn°t¦XLastUid©ÎLastCount ¤GªÌ¥i¥H¼W¶q¦¬¥ó¡C
12.为¦ó¦b¡§OnIDLEiamp¡¨¨Æ¥ó¡A经±`¬Ý¨ì¡§tnStatus:4099¡¨¡H
³q±`ªí¥ÜÊI络断开©ÎªA务¾¹¥D动终¤î IDLE 连±µ¡C
ÆÓ论¬O轮询还¬OIDLE 这¦b这¨½³£统¤@为IDLE¼Ò¦¡¡G¦Ó这Ïú¼Ò¦¡¤£会¤@ª½«ù续连±µ¡AªÅ闲时会断开¡AClientºÝ¥D动断开©ÎServer断开
当¦³·s邮¥ó¨ì达时¡A¨Æ¥ó¡§OnIDLENewMailArrives¡¨会«·s连±µ¤W¡A©P¦ÓÎ`©l¡C
13.IDLE¤ä«ù ¦h¤å¥ó夹吗¡H
暂时¤£¤ä«ù¡C
14.¦p¦ó§P别邮¥ó±µn¬O§_¬O¤j«¬邮¥ó¡H
¥i¥H³q过 "IMessageSummary.Size"ÚÌ©w®e¶q¤j¤p¡C
¥i参¦ÒDEMO¡G
mailkit_how iamp startidle.prg
15.¤ä«ù§ï变邮¥ó标识¦p¡G删°£¡A¤w读¡A¤w¦^Î`吗¡H
¥i参¦ÒDEMO¡G
mailkit_how iamp change flags async(seen answered deleted).prg
16.¦p¦ó设计ªí单¦¬发¥ó½c¼Ò块¡H
«Ø议¥D¬y¤è¦¡¡G
+----------------+---------------------+-----------------------+
| 账户¦Cªí | 邮¥óºKn¦Cªí | 邮¥ó详±¡ |
| (¦h账户¤Á换) | (显¥Ü发¥ó¤H¡B¥D题¡B | (显¥Ü§¹¾ã内®e¡Bªþ¥ó) |
| | 时间¡BºKn) | |
+----------------+---------------------+-----------------------+
20250317 en:
MailKit FAQ
1.How to obtain MailKit authorization?
MailKit is an open-source library under the MIT license. No additional authorization is required to use all features (including SMTP, POP3, IMAP, and IDLE modules).
For customized MailKit VFP port support, contact:
WeChat: Z68256904
Email: iswithzhz@outlook.com
MailKit offers two license types:
SMTP & POP3 Module Authorization
SMTP, POP3, IMAP, & IDLE Module Authorization
2.Should I use synchronous or asynchronous SMTP email sending?
Recommended: Use asynchronous sending (SendEmailAsync) to avoid blocking the main thread and improve
application responsiveness.
Use synchronous methods only in specific scenarios.
3.VFP is a single-threaded program. If the main thread is busy with a long task (e.g., SPT query),
will SendEmailAsync be delayed?
No.
Validation Steps:
Use Sleep(20 minutes) to block the VFP main thread.
Attach a 20MB file and execute mailkit_how_stmp_add_attachments_async_sending_email.prg.
Observe that the email is delivered before the main thread resumes.
Event callbacks (e.g., OnStmpSendEmailAsync) are queued and triggered after the main thread unblocks.
4.How to track email sending success with asynchronous SMTP?
Use a unique MessageId for each email.
Workflow:
Generate a MessageId when creating a draft.
Use SendEmailAsync and mark the draft as "sending."
In the OnStmpSendEmailAsync event, match the MessageId to update the draft status ("sent" or "failed").
Warn users if unsent drafts exist upon exit.
Reference Demo:
mailkit_how_stmp_send_email_async.prg
5.Does SMTP support multiple recipients?
Yes. Add multiple addresses to To, Cc, or Bcc.
6,Does SMTP support multiple attachments?
Yes. Use AddAttachment to add multiple files:
m.lcContentId = .AddAttachment("NetMailKit.dll", @lcErrorMsg)
Note: Email size limits vary by provider (e.g., 10MB¡V50MB). Exceeding limits may cause rejection.
Reference Demo:
mailkit_how_stmp_add_attachments_async_sending_email.prg
7.Does SMTP support CC, BCC, and Reply-To?
Yes.
Reference Demo:
mailkit_how_stmp_add_cc_bcc_replyto_in_sending_email.prg
8.Does POP3 fetch all emails or incrementally?
Default: Full download.
Incremental fetching via UIDL is possible but unreliable due to server UID retention policies (e.g., QQ deletes emails after 30 days).
Caution: Deleting server emails after download may affect mobile access.
9.Can IDLE support multiple accounts for auto-fetching?
Yes. Instantiate separate ImapClient instances for each account (e.g., oMailKit_IMAP_LELD, oMailKit_IMAP_LELDa).
Reference Demos:
mailkit_how_iamp_startidle.prg
mailkit_how_iamp_startidle(another account a).prg
mailkit_how_iamp_startidle(another account b).prg
Note: Manage thread and connection overhead for multi-account setups.
10.Can IMAP download emails as local files?
Yes. Use:
DownloadMessagesById() to save as .eml files.
DownloadMessageStreamsById() for large emails.
Parse local .eml files with MailKit.LoadLocalEml().
Reference Demos:
mailkit_how_iamp_sync_and_download_messages_by_uniqueid_to_local_eml_files.prg
mailkit_how_iamp_sync_and_download_messages_by_uniqueid_to_imimemessage.prg
mailkit_how_to_parse_local_eml_files.prg
11.Does IDLE fetch all emails on initial use? How to enable incremental fetching?
Initial IDLE: Full summary download.
Incremental: Use LastUid or LastCount.
12.Why does the OnIDLEiamp event frequently show tnStatus:4099?
Indicates network disconnection or server-initiated IDLE termination.
IDLE mode periodically reconnects; the OnIDLENewMailArrives event resumes listening.
13.Does IDLE support multiple folders?
Not currently supported.
14.How to check if an email is large?
Use IMessageSummary.Size.
Reference Demo:
mailkit_how_iamp_startidle.prg
15.Can email flags (e.g., deleted, read, replied) be modified?
Yes.
Reference Demo:
mailkit_how_iamp_change_flags_async(seen_answered_deleted).prg
16.How to design an email inbox/outbox interface?
Recommended Layout:
+---------------------+-------------------------+---------------------+
| Account List | Email Summary List | Email Details |
| (Multi-account | (Sender, Subject, Time, | (Full content, |
| switching) | Preview) | Attachments) |
+---------------------+-------------------------+---------------------+
iswith ¦b ¬P´Á¤@ ¤T¤ë 17, 2025 1:06 pm §@¤F²Ä 2 ¦¸×§ï |
|
¦^³»ºÝ |
|
 |
iswith
µù¥U®É¶¡: 2022-11-04 ¤å³¹: 92
²Ä 2 ¼Ó
|
µoªí©ó: ¬P´Á¥| ¤T¤ë 13, 2025 11:06 am ¤å³¹¥DÃD: |
|
|
¡C¡C¡C¡C¡C¡C¡C¡C |
|
¦^³»ºÝ |
|
 |
iswith
µù¥U®É¶¡: 2022-11-04 ¤å³¹: 92
²Ä 3 ¼Ó
|
µoªí©ó: ¬P´Á¤» ¤T¤ë 15, 2025 7:38 pm ¤å³¹¥DÃD: 20250315ª©¡AIDEL¼Ò¦¡尽±¡乱测,¥un§A·Q¨ìªº逻辑,¬Ý¬Ý¥¦¬O§_¥X错¡A当µM°£¤F§A°ª' |
|
|
20250315ª©¡AIDEL¼Ò¦¡尽±¡乱测,¥un§A·Q¨ìªº逻辑,¬Ý¬Ý¥¦¬O§_¥X错¡A当µM°£¤F§A°ª频发°e³QªA务¾¹µ¦¶V规则¡C |
|
¦^³»ºÝ |
|
 |
iswith
µù¥U®É¶¡: 2022-11-04 ¤å³¹: 92
²Ä 4 ¼Ó
|
µoªí©ó: ¬P´Á¤G ¤T¤ë 18, 2025 2:21 pm ¤å³¹¥DÃD: mailkit v1.0 ^¤åª© |
|
|
mailkit v1.0 ^¤åª© |
|
¦^³»ºÝ |
|
 |
iswith
µù¥U®É¶¡: 2022-11-04 ¤å³¹: 92
²Ä 5 ¼Ó
|
µoªí©ó: ¬P´Á¥| ¤T¤ë 20, 2025 11:58 am ¤å³¹¥DÃD: mailkit v1.0 ^¤åª© |
|
|
mailkit v1.0 ^¤åª© |
|
¦^³»ºÝ |
|
 |
iswith
µù¥U®É¶¡: 2022-11-04 ¤å³¹: 92
²Ä 6 ¼Ó
|
µoªí©ó: ¬P´Á¤é ¤T¤ë 23, 2025 9:57 am ¤å³¹¥DÃD: mailkit v1.0 ^¤åª© |
|
|
mailkit v1.0 ^¤åª© |
|
¦^³»ºÝ |
|
 |
iswith
µù¥U®É¶¡: 2022-11-04 ¤å³¹: 92
²Ä 7 ¼Ó
|
µoªí©ó: ¬P´Á¥| ¤T¤ë 27, 2025 9:59 am ¤å³¹¥DÃD: mailkit v1.0 ^¤åª© |
|
|
mailkit v1.0 ^¤åª© |
|
¦^³»ºÝ |
|
 |
iswith
µù¥U®É¶¡: 2022-11-04 ¤å³¹: 92
²Ä 8 ¼Ó
|
|
¦^³»ºÝ |
|
 |
iswith
µù¥U®É¶¡: 2022-11-04 ¤å³¹: 92
²Ä 9 ¼Ó
|
µoªí©ó: ¬P´Á¤@ ¥|¤ë 14, 2025 12:40 pm ¤å³¹¥DÃD: 请ûñ¦£§ë递¤@«Ê邮¥ó给§Ú |
|
|
§Ú开发¤F¤@个MailkitVFP¡A§Ú·Q试þÓ让ªºªB¤Í§Q¥Î¦UÏú¦Uý©ªºªº邮¥ó¨t统给§Ú§ë递¤@«Ê邮¥ó¡A§Ú¬Ý¬Ý¸ÑªR邮¥ó¥¿¤åªº逻辑¬O§_¥¿±`¡C谢谢¤j®a给¤©ûñ§U
Email:68256904@qq.com |
|
¦^³»ºÝ |
|
 |
iswith
µù¥U®É¶¡: 2022-11-04 ¤å³¹: 92
²Ä 10 ¼Ó
|
µoªí©ó: ¬P´Á¤G ¥|¤ë 15, 2025 12:31 pm ¤å³¹¥DÃD: mailkit v1.02 |
|
|
mailkit v1.02
0.¦p¦ó开©l¡H
±z»Ýn¦b¡§mailkit.prg¡¨将账户Password设¸m¥¿ÚÌ¡A¥H¤Î¨C个实¨Ò对应Email账户UserName
https://down.bc-cn.net/12766.html |
|
¦^³»ºÝ |
|
 |
iswith
µù¥U®É¶¡: 2022-11-04 ¤å³¹: 92
²Ä 11 ¼Ó
|
|
¦^³»ºÝ |
|
 |
|