Hi,
Please share source code of Sending mail (IIS-SMTP) with attachment in .asp.net 3.5 version os with windows 7..
Thanks
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Dhaval PatelRank #1,023 · 1.9K reputationPosted Sep 16, 2012, 10:15 PM EDT
mMailMessage.From = new MailAddress("MailAddress", "Display name");
mMailMessage.Subject = strSubject;
mMailMessage.IsBodyHtml = true;
mMailMessage.Priority = MailPriority.Normal;
Attachment attach = new Attachment(strFilePath);
mMailMessage.Attachments.Add(attach);
return "Success";
if this post help you than mark as "Accepted"
RanjithKumar chiguruvada133 reputationPosted Sep 17, 2012, 4:53 AM EDT
Please try this sample.
using System.Net.Mail;
protected void btnSubmit_Click(object sender, EventArgs e)
{
SmtpClient mail = new SmtpClient();
//create the mail message
MailMessage message = new MailMessage();
try
{
// USING SYSTEM.NET.MAIL NAMESPACE
//set the addresses
message.From = new MailAddress(txtEmail.Text, txtName.Text);
message.To.Add(new MailAddress("[email protected]","RavindraBabu"));
message.To.Add(new MailAddress(" EmailAddrees @ gmail .com", "RK Info"));
message.To.Add(new MailAddress(" EmailAddrees @ gmail .com","RK Info"));
//set the content
message.Subject = "Email Created by RK";
message.IsBodyHtml = true;
message.Body = txtRequest.Text;
//add an attachment from the filesystem
message.Attachments.Add(new Attachment(@"G:\Ranjith.txt"));
mail.Send(message);
// USING SYSTEM.WEB.MAIL NAMESPACE
// string smtpip = ConfigurationManager.AppSettings["smtpip"].ToString();
//string smtpip = ConfigurationManager.AppSettings["smtpip"].ToString();
//message.From = "[email protected]";
//message.To = txtEmail.Text;
//message.Subject = "RK Sample";
//message.Body = txtRequest.Text;
//message.BodyFormat = System.Web.Mail.MailFormat.Html;
//SmtpMail.SmtpServer = smtpip;
//SmtpMail.Send(message);
lblStatus.Text = "Email Successfully sent.";
}
catch(Exception ex) {
lblStatus.Text = "Send Email Fail" + ex.Message ;
}
}
and in web.config file write the following.
Shivanand ArurRank #920 · 2.3K reputationPosted Sep 17, 2012, 10:54 PM EDT
http://www.c-sharpcorner.com/Blogs/10044/how-we-can-send-async-mail-using-Asp-Net.aspx