使用 C# for Windows-mobile 将文本文件附加到邮件

Attach text file to mail using C# for Windows-mobile

我有这个示例 C# 代码,用于通过 Windows-Mobile 6.5 发送邮件:

EmailMessage message = new EmailMessage();
 Recipient myrecipient = new Recipient("Gmail", "MyMail@gmail.com");
 message.To.Add(myrecipient);
 message.Subject = "test from Windows-Mobile";                          
 message.BodyText = "this is the test from Windows-Mobile";        
 message.Send("Gmail");                                                
 MessagingApplication.Synchronize("Gmail");                     
 SetForegroundWindow(this.Handle);     
  1. 如何发送多个邮件地址?

  2. 如何将文本文件附加到邮件?

EmailMessage message = new EmailMessage();
 Recipient myrecipient = new Recipient("Gmail", "MyMail@gmail.com");
 message.To.Add(myrecipient);
 //Adding more To address
 message.To.Add(myrecipient2);
 message.To.Add(myrecipient3);
 //Adding more CC address
 message.Cc.Add(myrecipient4);
 message.Cc.Add(myrecipient5);
 //Adding more Bcc address
 message.Bcc.Add(myrecipient6);
 message.Bcc.Add(myrecipient7);
 message.Subject = "test from Windows-Mobile";                          
 message.BodyText = "this is the test from Windows-Mobile";        
 //Adding attachments
 message.Attachments.Add("TextFilePath");
 message.Send("Gmail");                                                
 MessagingApplication.Synchronize("Gmail");                     
 SetForegroundWindow(this.Handle);   

试试这个:

要附加包含更多详细信息的文件,例如 name/size。

Attachment attachment = new Attachment(outputFile, MediaTypeNames.Text.Html);
                ContentDisposition disposition = attachment.ContentDisposition;
                disposition.CreationDate = File.GetCreationTime(outputFile);
                disposition.ModificationDate = File.GetLastWriteTime(outputFile);
                disposition.ReadDate = File.GetLastAccessTime(outputFile);
                disposition.FileName = Path.GetFileName(outputFile);
                disposition.Size = new FileInfo(outputFile).Length;
                disposition.DispositionType = DispositionTypeNames.Attachment;
                message.Attachments.Add(attachment);
                smtp.Send(message);

link 参考:

https://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.attachments%28v=vs.110%29.aspx