感谢您关注我的问题。
我正在尝试找出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);问题是我不知道如何添加附件。上面的行应该是中间的其他东西,在那里我实际告诉它我想要附加的文件。在这件事上的任何帮助都将非常感谢。
再次感谢!
发布于 2011-08-24 12:03:41
根据此MSDN documentation,您可以将附件的文件名指定为参数。因此,您可以将fullpath作为字符串参数提供。
发布于 2012-06-22 10:06:42
他们有可以用来构建电子邮件附件的AttachmentBase。但是,我们不能将AttachmentBase实例添加到电子邮件的附件中。
我认为Attachment类应该继承自AttachmentBase。我认为这可能是一个缺陷。
https://stackoverflow.com/questions/7165390
复制相似问题