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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Shivanand ArurPosted Sep 18, 2012, 2:54 AM
http://www.c-sharpcorner.com/Blogs/10044/how-we-can-send-async-mail-using-Asp-Net.aspx
RanjithKumar chiguruvadaPosted Sep 17, 2012, 8:53 AM
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.
Dhaval PatelPosted Sep 17, 2012, 2:15 AM
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"