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
My current code is given below
public void SendMail()
{
try
{
string receiverEmailId = "name@exmp.com";
string senderName = ConfigurationManager.AppSettings["From"].ToString();
string mailServer = ConfigurationManager.AppSettings["SMTPServer"].ToString(); ;
string senderEmailId = ConfigurationManager.AppSettings["SMTPUserName"].ToString();
string password = ConfigurationManager.AppSettings["SMTPPasssword"].ToString();
var fromAddress = new MailAddress(senderEmailId, senderName);
var toAddress = new MailAddress(receiverEmailId, "Alen");
string subject = "subject";
string body = "body.";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential(fromAddress.Address, password)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
}
catch (Exception ex)
{
}
}
Here is a code...
create object of
Attachment
class with file name and add it into message's Attachments propertySending email with attachment in ASP.Net with a simple coding. In this article I will show you, how you can do this.
Index.aspx
Index.aspx.cs
https://suryarpraveen.wordpress.com/2017/08/22/how-to-send-email-with-attachment-in-asp-net/
Did you check out MailMessage.Attachments property (see MSDN)?
Reference