How to send mail to another email id with attachment file

C# Code:

Attachment at = new Attachment(Server.MapPath(MemberPic)); //for attached file.... 'MemberPic' is file path , is string format…
                    MailMessage Msg = new MailMessage();
                    string FromMail = "support@softtechsolving.com";
                    string Password = "XXXXXX"// "XXXXXX" is sender password…
                    Msg.From = new MailAddress(FromMail);
                    // Recipient e-mail address..
                    string ToMail = "softtechsolving@gmail.com";   //Receiver email id…
                    Msg.To.Add(ToMail);
                    string MsgBody = "Thank you…, Softtechsolving.. plz find attached file..";
                    AlternateView htmlMsgView = AlternateView.CreateAlternateViewFromString(MsgBody, null, MediaTypeNames.Text.Html);
                    Msg.AlternateViews.Add(htmlMsgView);
                    Msg.Subject = "Soft-Tech Solving;
                    Msg.Body = MsgBody;

                    //send the message
                    SmtpClient smtp = new SmtpClient("mail.softtechsolving.com");

                    //to authenticate we set the username and password properites on the SmtpClient
                    smtp.Credentials = new NetworkCredential(FromMail, Password);
                    Msg.Attachments.Add(at);
                    smtp.Send(Msg);

Namespace:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;
using System.Net;
using System.Net.Mail;

using System.Net.Mime;

Popular posts from this blog

How to protect your Drive/Flash USB Drive (Pen Drive) with Password without using any software