0
電子郵件+附件(vCard)發送。如何用class(localhost)發送郵件?
我不知道我在做什麼錯,搜索類似的問題2天,但沒有問題/解決方案在Stackoverflow或谷歌適合我的描述。
因爲我所著我的代碼diffrently
發送郵件+附件類:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Configuration;
using System.Net.Mail;
using System.Net.Configuration;
using Compulutions.Net;
using Compulutions.Web;
using System.IO;
using System.Web.Mail;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web.Services.Description;
// System.Web.Mail.SmtpMail.SmtpServer
// using System.Web.Mail.SmtpClient;
namespace vCardGenerator.Website
{
public class SendvCard
{
public void MailvCard(string recipient, string filename)
{
Mailer smtp = new Mailer("localhost");
/* SMTP - port 25 */
smtp.AddAttachment(filename); //.vcf file Path
smtp.FromAddress = new MailAddress ("[email protected]");
smtp.Subject = "vCard";
smtp.MailBody = "Attachment is a vCard";
smtp.AddRecipient(recipient);
#if !DEBUG
try
{
#endif
smtp.SendMail();
#if !DEBUG
}
catch (Exception ex)
{
Response.Write("Exception Occured: " + ex);
//Responds.Write("Sending vCard Failed! Please try again")
}
#endif
// File.Delete(filename);
// vCard.vcf Delete after being send
FileInfo DeleteFileInfo = new FileInfo(filename);
/* FileInfo DeleteFileInfo = new FileInfo("C:\\local\\vCardGenerator.Website" + "\\" + "FirstName_LastName" + ".vcf");
if (DeleteFileInfo.Exists)
File.Delete("C:\\local\\vCardGenerator.Website" + "\\" + "FirstName_LastName" + ".vcf"); */
}
}
}
按鈕發送:
protected void btnSend_Click(object sender, EventArgs e)
{
// Send mail with attachment
using (Attachment data = new Attachment("C:\\local\\vCardGenerator.Website\\" + "FirstName_LastName.vcf", MediaTypeNames.Application.Octet))
{
SendvCard smtp = new SendvCard();
}
lblStatus.Text = "Send to:" + " " + txtMail.Text;
FileInfo DeleteFileInfo = new FileInfo("C:\\local\\vCardGenerator.Website" + "\\" + "FirstName_LastName" + ".vcf");
if (DeleteFileInfo.Exists)
File.Delete("C:\\local\\vCardGenerator.Website" + "\\" + "FirstName_LastName" +".vcf");
}
}
}
願意提供任何其他/如果需要更多信息。
試圖獲得專業人士的幫助,所以至少給我一個解決方案,在燃燒我之前。
此致
絕望的生物。
謝謝,我編輯了它。但現在我從我的web.config – Lobato
@Rafael,我的郵件設置出現問題 - 您將不得不發佈有關您的新問題的新問題。請提供您收到的所有錯誤消息以及您的web.config副本。 –
好的,我必須這樣做..謝謝(標記爲已回答!) – Lobato