电子邮件 + 附件 (vCard) 发送。
我不知道我做错了什么,搜索了 2 天的类似问题,但 Stackoverflow 或 Google 上的问题/解决方案不符合我的描述。
因为我用不同的方式编写了我的代码
发送邮件+附件类:
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 ("random@mail.com");
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");
}
}
}
如果需要,愿意提供任何其他/更多信息。
试图得到专业人士的帮助,至少在烧死我之前给我一个解决方案。
真诚的,
绝望的生物。