JCWEBHOST
asked on
Cannot access a closed Stream
Hey guys, i am geting this error: Cannot access a closed Stream, while trying to send an attach email.
here my code:
please help
here my code:
public MemoryStream Ms
{
get { return ms; }
set { ms = value; }
}
public string SendMail()
{
string erorr = "";
try
{
System.Net.Mail.MailMessage MailMass = new System.Net.Mail.MailMessage();
MailMass.From = new System.Net.Mail.MailAddress("ben@intercity.jcwebhostza.com");
MailMass.To.Add(new System.Net.Mail.MailAddress(To));
MailMass.Subject = Subject;
MailMass.Body = Body;
MailMass.IsBodyHtml = true;
MailMass.ReplyTo = new System.Net.Mail.MailAddress("ben@intercity.jcwebhostza.com");
MailMass.Priority = System.Net.Mail.MailPriority.Normal;
System.Net.Mail.SmtpClient smtpC = new System.Net.Mail.SmtpClient();
System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("ben@intercity.jcwebhostza.com", "ben01int");
if (Ms != null && Pdf_name != "")
{
MemoryStream open_ms = Ms;
open_ms.Position = 0;
using (Attachment att = new Attachment(open_ms, Pdf_name, MediaTypeNames.Application.Pdf))
{
{
MailMass.Attachments.Add(att);
}
}
}
smtpC.Host = "mail.intercity.jcwebhostza.com";
smtpC.Port = 25;
smtpC.UseDefaultCredentials = false;
smtpC.Credentials = basicAuthenticationInfo;
smtpC.Send(MailMass);
}
catch (Exception E)
{
erorr = E.Message.ToString();
}
return erorr;
please help
Hi! Where do you create and close ms?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.