Cannot email the generated pdf

nexpearie

New Member
I am writing code to email a generated pdf file but it fails to send the email and throws below error."4.3.2 Service not available, closing transmission channel" I tried copying the code of try block in to the catch block. In this case the email is being sent but then I cannot open the attached pdf file. It give below error"it is either not supported file type or it is damaged(for example it was sent as an email attachment and wasn't correctly decoded)"Can anyone suggest what I am doing wrong here. Thanks in advance. Below is the code:\[code\]try { //create document string temp = System.Guid.NewGuid().ToString(); sPathToWritePdfTo = @Server.MapPath(@"Form\onlineform" + temp + ".pdf"); //sPathToWritePdfTo = "\\AAA\\Form\\onlineform" + temp + ".pdf"; FileStream fileStream = new FileStream(PathToWritePdf, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite); fileStream.Close(); //open document and write onto it DocPDF.Save(PathToWritePdf); //store PDF location string adminID = "[email protected]"; Attachment userPDF = new Attachment(PathToWritePdf); MailMessage msg = new MailMessage(); msg.From = new MailAddress(adminID); msg.To.Add(new MailAddress(txtEvalEmail.Text)); msg.Subject = "Hello!! in try"; msg.Body = "Hello " msg.Attachments.Add(userPDF); SmtpClient SmtpMail = new SmtpClient(); SmtpMail.Host = "basic.smtp.aa.edu"; SmtpMail.Port = 25; SmtpMail.Send(msg); } catch { string adminID = "[email protected]"; Attachment userPDF = new Attachment(PathToWritePdf); MailMessage msg = new MailMessage(); msg.From = new MailAddress(adminID); msg.To.Add(new MailAddress(txtEvalEmail.Text)); msg.Subject = "Hello! in catch"; msg.Body = "Message Body in catch"; msg.Attachments.Add(userPDF); SmtpClient SmtpMail = new SmtpClient(); SmtpMail.Host = "basic.smtp.aa.edu"; SmtpMail.Port = 25; SmtpMail.Send(msg); }\[/code\]
 
Back
Top