How to Send Email With Attachment In Asp.Net

后端 未结 6 948
梦谈多话
梦谈多话 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:18

    public static bool SendMail(string strFrom, string strTo, string strSubject, string strMsg)
        {            
            try
            {                
                // Create the mail message
                MailMessage objMailMsg = new MailMessage(strFrom, strTo);
    
                objMailMsg.BodyEncoding = Encoding.UTF8;
                objMailMsg.Subject = strSubject;
                objMailMsg.Body = strMsg;
                Attachment at = new Attachment(Server.MapPath("~/Uploaded/txt.doc"));
                objMailMsg.Attachments.Add(at);
                objMailMsg.Priority = MailPriority.High;
                objMailMsg.IsBodyHtml = true;
    
                //prepare to send mail via SMTP transport
                SmtpClient objSMTPClient = new SmtpClient();
                objSMTPClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
                objSMTPClient.Send(objMailMsg);
                return true;                
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }  
    

    Reference

提交回复
热议问题