謝謝你看我的問題。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);
的問題是,我無法弄清楚如何獲取附件添加。上面的代碼應該是中間的其他東西,我實際上告訴它我要附加的文件。任何有關此事的幫助將不勝感激。
再次感謝!
你的意思是你想要多個附件或類似的東西? –
只有一個附件,一個zip文件 – jnsohnumr
您使用什麼代碼來附加以及出現什麼錯誤?還是說Attachment類沒有向其中添加文件所需的API? – Quibblesome