[英]Can I access the sent Email folder using SmtpClient and delete the sent email?
我正在使用SmtpClient
發送帶附件的 email。
我可以使用SmtpClient
從已發送的文件夾中刪除已發送的 email 嗎?
這是我的代碼:
ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
using var mailMessage = new MailMessage();
mailMessage.To.Add(new MailAddress(s));
mailMessage.From = new MailAddress("mohammad.jouhari@gmail.com");
mailMessage.Subject = "Remote Freelance Web Developer,Mohammad Jouhari Latest CV";
mailMessage.Body = "Dear Hiring Manager,\r\n\r\n Please find attached CV.\r\n\r\n " +
"My work sample:https://github.com/mohammadjouhari.\r\n\r\n" +
"My linkedin Profile: https://www.linkedin.com/in/mohammad-jouhari-42461330/";
string pdfFilePath = "C:\\Users\\m_243\\OneDrive\\Desktop\\microsoft documentation\\.net core\\SendEmailTest" +
"\\SendEmailTest\\wwwroot\\MohammadJouhariCV.pdf";
byte[] bytes = System.IO.File.ReadAllBytes(pdfFilePath);
var attachment = new Attachment(new MemoryStream(bytes), "MohammadJouhariCV.PDF");
mailMessage.Attachments.Add(attachment);
NetworkCredential loginInfo = new NetworkCredential("mohammad.jouhari@gmail.com", ""); // password for connection smtp if you don't have have then pass blank
SmtpClient _smtpClient = new SmtpClient();
_smtpClient.Host = "smtp.gmail.com";
_smtpClient.Port = 587;
_smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
_smtpClient.EnableSsl = true;
_smtpClient.UseDefaultCredentials = false;
_smtpClient.Credentials = loginInfo;
_smtpClient.Send(mailMessage); // _smtpClient will be disposed by container
_smtpClient.Dispose();
我正在嘗試這段代碼
Pop3Client pop3 = new Pop3Client();
pop3.Host = "smtp.gmail.com";
pop3.Username = "mohammad.jouhari@gmail.com";
pop3.Password = "";
pop3.Port = 587;
pop3.EnableSsl = true;
pop3.Connect();
pop3.DeleteAllMessages();
pop3.Dispose();
我在pop3.Connect();
無法確定幀大小或收到損壞的幀
否DELE
命令從收件箱中刪除,而不是從發件箱中刪除。 從其他郵箱中刪除電子郵件是通過特定於平台的 api 完成的 - 在 Gmail 中執行此操作的方式將不同於 Outlook。例如,Microsoft 使用其 Graph api 來管理郵箱。 Google 稱它們為“標簽”而不是“郵箱”,一個 email 可以關聯多個 label
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.