感谢您查看我的问题。
我正在试图找出OpenNetCF.Net.Mail的附件。这是我的SendMail函数的代码:
public static void SendMessage(string subject,
string messageBody,
string fromAddress,
string toAddress,
string ccAddress)
{
MailMessage message = new MailMessage();
SmtpClient client = new SmtpClient();
MailAddress address = new MailAddress(fromAddress);
// Set the sender's address
message.From = address;
// Allow multiple "To" addresses to be separated by a semi-colon
if (toAddress.Trim().Length > 0)
{
foreach (string addr in toAddress.Split(';'))
{
message.To.Add(new MailAddress(addr));
}
}
// Allow multiple "Cc" addresses to be separated by a semi-colon
if (ccAddress.Trim().Length > 0)
{
foreach (string addr in ccAddress.Split(';'))
{
message.CC.Add(new MailAddress(addr));
}
}
// Set the subject and message body text
message.Subject = subject;
message.Body = messageBody;
// TODO: *** Modify for your SMTP server ***
// Set the SMTP server to be used to send the message
client.Host = "smtp.dscarwash.com";
string domain = "dscarwash.com";
client.Credentials = new SmtpCredential("mailuser", "dscarwash10", domain);
// Send the e-mail message
try
{
client.Send(message);
}
catch (Exception e)
{
string data = e.ToString();
}
}
应该通过以下方式调整它以允许附件:
Attachment myAttachment = new Attachment();
message.Attachments.Add(myAttachment);
问题在于我无法弄清楚如何添加附件。上面的行应该是中间的其他东西,我实际上告诉它我想要附加什么文件。任何有关此事的帮助将不胜感激。
再次感谢!
答案 0 :(得分:0)
根据此MSDN documentation,您可以将附件的文件名指定为参数。因此,您可以将完整路径作为字符串参数。
答案 1 :(得分:0)
他们有AttachmentBase
可用于构建电子邮件附件。但是,我们无法将AttachmentBase
的实例添加到电子邮件的附件中。
我认为Attachment
类应该继承自AttachmentBase
。我认为这可能是一个缺陷。