The problem:
I want that users can send me mails with attachments. They can choose the file with an input file button in html. The problem is that it can't find the file. It works fine without attachments.
I get this error
File C: Program Files (x 86) ExpressGIPENGLISH .pptx IIS cannot be found.
Does anybody have any ideas?
What I tried:
Tried first uploading the file to that location but still doesn't work.
Input file button
<INPUT type=file id=File1 name=File1 runat="server" > </asp:Content>
C# Code
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(System.IO.Path.GetFileName(File1.PostedFile.FileName));
MailMessage mail = new MailMessage("d***[email protected]", "d***[email protected]");
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("d***[email protected]", "");
mail.BodyEncoding = Encoding.UTF8;
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
mail.Subject = TxtOnderwerp.Text;
mail.Body = TxtMail.Text;
mail.Body += Environment.NewLine + "Van " + TxtNaam.Text;
mail.Body += Environment.NewLine + " Deze persoon is te bereiken op het mail adres " + TxtEmail.Text + " of op het nummer " + TxtTel.Text;
mail.Attachments.Add(attachment);
client.Send(mail);
Result: I want that a user can send me a mail with an attachment that he chose himself that is on his computer. And that I can receive the mail and open the attachment. Thank you in advance
HttpPostedFile.InputStream
directly to createAttachment
... no saving, no unnecessary MemoryStream – Woodberry