TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Vivek Kumar Vishwas
NA
115
56.3k
Sending mail with attachment file with direct path
Nov 3 2017 7:47 AM
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;
}
}
Reply
Answers (
3
)
How to save exported PDF file into specified folder
How Create cart In Restaurant Website ?..