Tech
Forums
Jobs
Books
Events
Live
Interviews Prep
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
3
Reply
Sending mail with attachment file with direct path
Vivek Kumar Vishwas
Nov 3 2017 7:47 AM
115
Reply
Hi,
I am having an error while passing a direct path to mail attachment.
Please check and update me soon. Dead line till today.
// Code as below
public
void
sendmail_to_user()
{
string
to = txtemail.Text;
//To address
string
from =
"
[email protected]
"
;
//From address
string
[] Multiple = to.Split(
','
);
MailMessage message =
new
MailMessage();
message.From =
new
MailAddress(from);
foreach
(
string
multiple_email
in
Multiple)
{
message.To.Add(
new
MailAddress(multiple_email));
}
//http://localhost:1728/InsertRecordMSAccess(CSharp)/file/pitamber.pdfhttp://localhost:1728/InsertRecordMSAccess(CSharp)/file/CrystalReportViewer1.pdf
//message.Attachments.Add(new Attachment("/file/" + txtContact.Text + ".pdf"));
// Below i am passing path of my document
message.Attachments.Add(
new
Attachment(
"file/CrystalReportViewer1.pdf"
));
//if (FileUpload2.HasFile)//Attaching document
//{
// string FileName = Path.GetFileName(FileUpload2.PostedFile.FileName);
// message.Attachments.Add(new Attachment(FileUpload2.PostedFile.InputStream, FileName));
//}
string
mailbody =
"Message Body"
;
message.Subject =
"Subject"
;
message.Body = mailbody;
message.BodyEncoding = Encoding.UTF8;
message.IsBodyHtml =
true
;
SmtpClient client =
new
SmtpClient(
"smtp.gmail.com"
, 587);
//Gmail smtp
System.Net.NetworkCredential basicCredential1 =
new
System.Net.NetworkCredential(
"
[email protected]
"
,
"Password"
);
client.EnableSsl =
true
;
client.UseDefaultCredentials =
false
;
client.Credentials = basicCredential1;
try
{
client.Send(message);
}
catch
(Exception ex)
{
throw
ex;
}
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
How to save exported PDF file into specified folder
How Create cart In Restaurant Website ?..