Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
AnswerRe: how to call server side function from jquery Pin
Keith Barrow12-May-14 22:41
professionalKeith Barrow12-May-14 22:41 
GeneralMy Vote of 1 Pin
Keith Barrow13-May-14 0:41
professionalKeith Barrow13-May-14 0:41 
GeneralRe: My Vote of 1 Pin
Pete O'Hanlon13-May-14 1:27
mvePete O'Hanlon13-May-14 1:27 
GeneralRe: My Vote of 1 Pin
OriginalGriff13-May-14 2:41
mveOriginalGriff13-May-14 2:41 
QuestionOpenFileName under WinPE Pin
vacko12-May-14 20:41
vacko12-May-14 20:41 
QuestionC# kinect game Pin
Member 1080779612-May-14 9:32
Member 1080779612-May-14 9:32 
AnswerRe: C# kinect game Pin
OriginalGriff12-May-14 20:46
mveOriginalGriff12-May-14 20:46 
QuestionC# Asp.Net Web App - Generating Outlook Email for Download Pin
MatiTuk12-May-14 9:09
MatiTuk12-May-14 9:09 
I have a requirement to generate an Outlook email that is downloaded after a new user is created through the UI. The client wants to review the email prior to it being sent to the user, this is why it needs to be downloaded. I cannot use Microsoft.Interop because this is a web application and Office is not installed on our servers.

I have created a html template for the email body and I am using MailMessage to generate the email. My current code sends the file to a pickup directory and then I try to download the file as an eml file. This works, except the body of the email is missing from the download. If I go to the server and view the file it does have the body. What am I missing from the download piece of code? Thank you for any thoughts and suggestions.

C#
public static void sendNewUserEmail(string username, string password, string url, List<string> projects, string client)
        {
            try
            {

                var response = System.Web.HttpContext.Current.Response;
                var emailfilepath = @"C:\LogFiles\FE\Emails\NewUser\";
                DateTime now = DateTime.Now;
                now.ToString("yyyy-mm-dd");

                var projectlist = String.Join(", ", projects.ToArray());
                string fromemail = "support@noreply.com";
                string subject = "New Account Created - " + client + ": " + projectlist;

                MailMessage message = new MailMessage();

                using (StreamReader reader = File.OpenText(@"C:\inetpub\fe\Interior\UserAdmin\NewUserEmail.html"))
                {
                    message.From = new MailAddress(fromemail);
                    message.To.Add(username);
                    message.Subject = subject;
                    message.Priority = MailPriority.High;
                    message.IsBodyHtml = true;

                    message.Body = reader.ReadToEnd();

                    message.Body = message.Body.Replace("{Password}", password);
                    message.Body = message.Body.Replace("{Project}", projectlist);
                    message.Body = message.Body.Replace("{URL}", url);
                }

                SmtpClient smtp = new SmtpClient("mysmtphost");
                smtp.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                smtp.PickupDirectoryLocation = emailfilepath;
                smtp.Send(message);

                var file = new System.IO.FileInfo(emailfilepath);

                string filename = file.Name.ToString();

                response.BufferOutput = true;

                response.Clear();
                response.ClearHeaders();
                response.ContentEncoding = Encoding.Unicode;

                response.AddHeader("content-disposition", "attachment; filename=NewUserEmail_" + client + "_.eml");
                response.AddHeader("Content-Length", file.Length.ToString(CultureInfo.InvariantCulture));
                response.ContentType = "application/octet-stream";
                response.WriteFile(emailfilepath + file.FullName);
                response.End();

                DeleteFile(filename);

            }
            catch (Exception ex)
            {
                string message = ex.Message;
                string stacktrace = ex.StackTrace;
                string source = ex.Source;
                string method = "sendNewUserEmail";

                Logger.LogFile(source, message, stacktrace, method);
            }            
        }


modified 12-May-14 15:46pm.

AnswerRe: C# Asp.Net Web App - Generating Outlook Email for Download Pin
Bernhard Hiller12-May-14 21:59
Bernhard Hiller12-May-14 21:59 
GeneralRe: C# Asp.Net Web App - Generating Outlook Email for Download Pin
MatiTuk13-May-14 2:38
MatiTuk13-May-14 2:38 
QuestionUse GPU from C# Pin
AmbiguousName12-May-14 6:52
AmbiguousName12-May-14 6:52 
AnswerRe: Use GPU from C# Pin
Eddy Vluggen12-May-14 7:43
professionalEddy Vluggen12-May-14 7:43 
GeneralRe: Use GPU from C# Pin
AmbiguousName12-May-14 7:49
AmbiguousName12-May-14 7:49 
GeneralRe: Use GPU from C# Pin
Eddy Vluggen12-May-14 8:38
professionalEddy Vluggen12-May-14 8:38 
GeneralRe: Use GPU from C# Pin
AmbiguousName12-May-14 19:18
AmbiguousName12-May-14 19:18 
GeneralRe: Use GPU from C# Pin
Eddy Vluggen13-May-14 7:04
professionalEddy Vluggen13-May-14 7:04 
QuestionHow can i make this program Parrallel ? Pin
Member 1037568411-May-14 11:51
Member 1037568411-May-14 11:51 
AnswerRe: How can i make this program Parrallel ? Pin
Phil Martin11-May-14 12:57
professionalPhil Martin11-May-14 12:57 
GeneralRe: How can i make this program Parrallel ? Pin
Bernhard Hiller11-May-14 22:06
Bernhard Hiller11-May-14 22:06 
GeneralRe: How can i make this program Parrallel ? Pin
Rob Philpott11-May-14 22:24
Rob Philpott11-May-14 22:24 
GeneralRe: How can i make this program Parrallel ? Pin
Phil Martin11-May-14 22:39
professionalPhil Martin11-May-14 22:39 
GeneralRe: How can i make this program Parrallel ? Pin
Phil Martin11-May-14 22:47
professionalPhil Martin11-May-14 22:47 
GeneralRe: How can i make this program Parrallel ? Pin
SledgeHammer0112-May-14 9:33
SledgeHammer0112-May-14 9:33 
GeneralRe: How can i make this program Parrallel ? Pin
Phil Martin12-May-14 11:15
professionalPhil Martin12-May-14 11:15 
QuestionStored procedures - Northwind database Pin
Vexy11-May-14 9:58
Vexy11-May-14 9:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.