在电子邮件中发送附件

时间:2014-08-04 13:31:32

标签: c# asp.net

我希望用户应该获得CV而不是CVFilePath。我可以按照调用的方式获取CVFilePath。但是无法获得Resume doc。任何人都可以帮我如何在按钮点击上发送简历。

请参阅代码供您参考。

按钮点击代码: -

protected void btnSubmit_Click(object sender, EventArgs e)
{
    if (uploadCV.PostedFile.ContentLength > 0)
    {
        var fileName = Path.GetFileNameWithoutExtension(uploadCV.PostedFile.FileName);
        var ext = Path.GetExtension(uploadCV.PostedFile.FileName);
        fileName = fileName + "_" + Guid.NewGuid() + "." +      Path.GetExtension(uploadCV.PostedFile.FileName).TrimStart('.');
        var path = Path.Combine(Server.MapPath(ResumeUploadFolerPath), fileName);
        if (!Directory.Exists(Server.MapPath(ResumeUploadFolerPath)))
        {
            Directory.CreateDirectory(Server.MapPath(ResumeUploadFolerPath));
        }
        uploadCV.PostedFile.SaveAs(path);
        applicant.CVFilePath = ResumeUploadFolerPath + "/" + fileName;
    }

    _careerHelper.Save(applicant);
    _presentation.SendApplicantEmail(applicant);
    _presentation.SendJobMail(applicant);
}
}

代码:发送给相应用户的邮件: -

public void SendJobMail(Applicant applicant)
{
    StringBuilder sbuilder = new StringBuilder();
    sbuilder.Append("<html xmlns=\"http://www.w3.org/1999/xhtml\"><body>");
    sbuilder.Append("<div>");
    sbuilder.Append("<p>An application for the job posting has been submitted</p>");
    sbuilder.Append("<table>");
    sbuilder.Append("<tr><td>Position</td><td>" + applicant.Job.Position + "</td></tr>");
    sbuilder.Append("<tr><td>Location</td><td>" + applicant.Job.Location + "</td></tr>");
    sbuilder.Append("<tr><td>Business Unit</td><td>" + applicant.Job.BusinessUnit + "</td></tr>");
    sbuilder.Append("<tr><td>Name</td><td>" + applicant.Firstname + " " + applicant.LastName + "</td></tr>");
    sbuilder.Append("<tr><td>Contact</td><td>" + applicant.ContactNumber + "</td></tr>");
    sbuilder.Append("<tr><td>Email</td><td>" + applicant.Email + "</td></tr>");
    sbuilder.Append("<tr><td>City</td><td>" + applicant.City + "</td></tr>");
    sbuilder.Append("</table>");
    sbuilder.Append("</div>");
    sbuilder.Append("</body></html>");

    MailMessage rblemail = new MailMessage();
    rblemail.From = new MailAddress(ConfigurationManager.AppSettings["FromEmail"]);
    rblemail.To.Add(new MailAddress(applicant.Job.EmailId1));
    rblemail.To.Add(new MailAddress(applicant.Job.EmailId2));
    rblemail.IsBodyHtml = true;
    rblemail.Subject = "Job Acknowledgement : " + applicant.Job.Position + " - " + applicant.Job.Location;
    rblemail.Body = sbuilder.ToString();

    Common ObjCom = new Common();
    ObjCom.SendEMail(rblemail);

}

1 个答案:

答案 0 :(得分:0)

我不知道您将附件附加到MailMessage对象的位置。

您应该可以使用CVFilePath将文件附加到电子邮件中,按照此tutorial

类似的东西:

System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(HttpContext.Current.Server.MapPath(applicant.CVFilePath));
rblemail.Attachments.Add(attachment);