我可以使用c#代码向多个用户发送带附件的邮件。我想删除使用c#从我的Gmail帐户发送的已发送邮件。有没有办法做到这一点。
我发送附件邮件的代码。
if (MailID1 != null)
{
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
try
{
mailidcount = MailID1.Split(',').Count();
mailids = new string[mailidcount];
mailids = MailID1.Split(',');
var Adminmail = "User@gmail.com";
var AdminPassword = "password123!";
var AdminSmtpclient = "smtp.gmail.com"
string sub = Formobj["Subject_Text"]+" " + Convert.ToDateTime(DateTime.Now.ToUniversalTime()).ToString("dd/MM/yyyy");
mail.Subject = sub;
mail.From = new System.Net.Mail.MailAddress(Adminmail);
mail.To.Add(mailids[0]);
if (mailidcount > 0)
{
for (int a = 1; a < mailidcount; a++)
{
mail.CC.Add(mailids[a]);
}
}
mail.Body = "<pre>" +Formobj["Message_Text"] +"</pre>";
mail.IsBodyHtml = true;
string filename;
string Filename = Path.GetFileName(Infile.FileName);
filename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "\\Content\\TrialFolder\\Filefolder\\" + Filename);
if (Infile.ContentLength > 0)
{
Infile.SaveAs(filename);
System.Net.Mail.Attachment attached;
attached = new System.Net.Mail.Attachment(filename);
mail.Attachments.Add(attached);
}
if (sub != null)
{
mail.IsBodyHtml = true;
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(AdminSmtpclient);
smtp.Host = AdminSmtpclient;
smtp.Port = "587";
smtp.UseDefaultCredentials = true;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential(Adminmail, AdminPassword);
smtp.Send(mail);
if (System.IO.File.Exists(filename) == true)
{
try
{
mail.Attachments.Dispose();
System.IO.File.Delete(filename);
mail.Dispose();
smtp.Dispose();
}
catch (Exception ex)
{
ViewBag.Message = ex.Message;
}
}
TempData["EmailMessage"] = "Your Message has been sent Successfully";
}
else
{
TempData["EmailMessage"] = "Please check Email Settings";
}
}
答案 0 :(得分:0)
gmail =&gt;的完整API https://developers.google.com/gdata/client-cs
答案 1 :(得分:0)
有一些第三方dll,例如OpenPOP,IMAP4
,您可以使用它们删除已发送的邮件。SMTP
仅用于sending mails