How to Send Email With Attachment In Asp.Net

后端 未结 6 945
梦谈多话
梦谈多话 2020-12-16 15:29

I need to attach an image with my email in asp.net the file is already added in the solution explorer but I dont know how to add this with my email please guide me

M

6条回答
  •  自闭症患者
    2020-12-16 16:10

    Here is a code...

    public void MailSend(string strfrom, string strto, string strSubject, string strBody, string resumename, string sresumename)
    {
        try
        {
            MailMessage msg = new MailMessage(strfrom, strto);// strEmail);
    
            msg.Bcc.Add("xx@xxxx.com");
            msg.Body = strBody;
            msg.Subject = strSubject;
            msg.IsBodyHtml = true;
            if (resumename.Length > 0)
            {
                Attachment att = new Attachment(Server.MapPath(VirtualPathUtility.ToAbsolute("~/User_Resume/" + resumename)));
                msg.Attachments.Add(att);
            }
            if (sresumename.Length > 0)
            {
                Attachment att1 = new Attachment(Server.MapPath(VirtualPathUtility.ToAbsolute("~/User_Resume/" + sresumename)));
                msg.Attachments.Add(att1);
            }
            System.Net.Mail.SmtpClient cli = new System.Net.Mail.SmtpClient("111.111.111.111",25);
            cli.Credentials = new NetworkCredential("nnnnnnn", "yyyyyy");
            cli.Send(msg);
            msg.Dispose();
            ScriptManager.RegisterStartupScript(this, this.GetType(), "message", "alert('Enquiery submitted sucessfully');", true);
        }
        catch (Exception ex)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "message", "alert('"+ex.Message+"');", true);
        }
    }
    

提交回复
热议问题