Solved

Build file without storing to the hard drive then add it as attachment

Posted on 2006-07-11
2
233 Views
Last Modified: 2010-04-16
How to make a file and place it as an attachment in an e-mail? My problem is how to build the CVS file. It would be great if it was possible to build it without saving anything to the hard drive.

This is how I send the e-mail.

    public void SendMail()
    {
        try
        {
            MailMessage mail2 = new MailMessage();
            mail2.To.Add("aahsdkjahsd@yahoo.com");
            mail2.From = new MailAddress(TxtEpost.Text, TxtEtternavnForrnavn.Text, System.Text.Encoding.UTF8);

            mail2.Subject = "Bestille katalog";
            mail2.SubjectEncoding = System.Text.Encoding.UTF8;

           
           
            Attachment atch = new Attachment("MyFile.CVS");
            mail2.Attachments.Add(atch);
           
            mail2.Body = "";

            mail2.BodyEncoding = System.Text.Encoding.UTF8;
            mail2.IsBodyHtml = false;
            mail2.Priority = MailPriority.High;
            //Add the Creddentials
            SmtpClient client2 = new SmtpClient();
            //For secure SMTP remove comments.....
            //client2.Credentials = new System.Net.NetworkCredential("jakslajsd@gmail.com", "password");
            //client2.Port = 587;//or use 587, 465
            client2.Host = "smtp.jaslkdj.com";
            //client2.EnableSsl = true;
            //client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);
            client2.Send(mail);
        }
        catch (Exception ex)
        {
            //Label1.Text += ex.ToString();
        }
0
Comment
Question by:m-jansen
2 Comments
 
LVL 3

Accepted Solution

by:
BBK_ earned 125 total points
ID: 17098438
There is no easy way to send attachment other than from a (any persistable medium)  disk. Normally when application need to send mail with attachments, the attachment will be created in windows temp folder ( So user will not have any permission issue) and add the file name to the attachment list
 You can use “Environment.GetEnvironmentVariable("TMP")” to get the temp folder of the user.
Save the CSV file there.
0
 

Author Comment

by:m-jansen
ID: 17117097
That sounds interesting. So if I create the attachment with a string and then use the content of this string to fill the csv file I can create a temporary file like a cookie on the hard drive with c# code?
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question