opennetcf.net.mail 附件帮助
感谢您查看我的问题。
我正在尝试找出 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);
问题是我无法弄清楚如何添加附件。上面的行应该是中间有其他东西,我实际上告诉它我想附加什么文件。任何有关此事的帮助将不胜感激。
再次感谢!
Thanks for looking at my question.
I am trying to figure out attachments for OpenNetCF.Net.Mail. Here is the code for my SendMail function:
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();
}
}
It is supposed to be a matter of tweaking it in the following way to allow attachments:
Attachment myAttachment = new Attachment();
message.Attachments.Add(myAttachment);
The problem is that I cannot figure out how to get the attachment to add. The lines above should be it with something else in the middle where I actually tell it what file I would like to attach. Any help on this matter will be greatly appreciated.
Thanks again!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据此 MSDN 文档,您可以指定附件的文件名作为参数。因此,您可以将完整路径作为字符串参数。
As per this MSDN documentation, you can specify the filename of the attachment as a parameter. Thus, you can give the fullpath as the string parameter.
他们有
AttachmentBase
可用于构建电子邮件附件。但是,我们无法将AttachmentBase
实例添加到电子邮件的附件中。我认为
Attachment
类应该继承于AttachmentBase
。我想这可能是一个缺陷。They have
AttachmentBase
which can be used to construct a email attachment. However, we cannot add the instance ofAttachmentBase
to the attachments of email message.I think the
Attachment
class should inherit fromAttachmentBase
. I think this maybe a defect.