Solved

Emails with blank attachments (PDF, DOC)

Posted on 2013-07-01
8
300 Views
Last Modified: 2013-07-14
Hello Experts,
On our website a user can upload a file. That file is saved to our database (SQL) and then an email  sent with the uploaded file as an attachment.
When we test on the  dev server everything works fine (so there is no problem with the code).
When we test on the  prod server the email comes with attachment that is 64b and blank. Both servers have same configuration. The only difference is that prod server has SSL.
Please, help. We keep receiving blank attachment.
Thanks.
0
Comment
Question by:kqureshi321
8 Comments
 
LVL 7

Expert Comment

by:Mohammed Tahir
Comment Utility
Are you facing this issue with all incomming emails (with attachement) or only emails coming from your application server?
0
 

Author Comment

by:kqureshi321
Comment Utility
Only the emails from the application server.
0
 
LVL 26

Expert Comment

by:skullnobrains
Comment Utility
you probably lack some checks when the file gets uploaded, but you need to debug a little bit more :

log downloaded file sizes or take a look in the database. if i'm right we'll need to see the upload code. if not the problem would rather be on the sending part and we'll need that code and one message's source
0
 

Author Comment

by:kqureshi321
Comment Utility
Below is a code to upload and send the attachment.

//ASP code
<strong>Resume:</strong> Please upload your resume </strong>. 
<asp:FileUpload ID="FileCv" runat="server" />
…..
<asp:LinkButton ID="LBtnSubmit" runat="server" Text="Submit" CssClass="btn" OnClick="LBtnSubmit_Click" />
           

//**********************************************************************
//CS code
protected void LBtnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                //save resume to db
               UploadResumeToDB();
               SendSEmail();
            }
            catch (Exception ex)
            {
                Response.Write(ex);
                LtError.Text = "An error has occurred while attempting to submit our    application. Please try again later, or contact a staff member if the error persists. <span style=\"display: none;\">" + ex.ToString() + "</span>";
            }
        }

private void UploadResumeToDB()
{
            String fileName = "";

            if (FileCv.HasFile && FileCv.PostedFile != null)
            {
                HttpPostedFile file = FileCv.PostedFile;
                fileName = FileCv.PostedFile.FileName;
                LetRes = new Byte[file.ContentLength];
                file.InputStream.Read(LetRes, 0, file.ContentLength);
            }

            //Save resume
            if (LetRes != null)
            {
                GDataAccess da = null;

                using (da = new GDataAccess(connString))
                {
                   //…. code that executes SP and saves file to DB no problem here. Everything is working.
                }
            }
        }


private void SendSEmail()
        {
          String emailTo = myEmail@nyc.org;

            String sb =”EmailText”;
         
            String uploadFileName = Path.GetFileName(FileCv.PostedFile.FileName);
            Attachment cv = new Attachment(FileCv.FileContent, uploadFileName);
            GUtility.SendEmail("NYC Notification", sb, emailTo, cv);
          }


//UTILITIES 

public class GUtility
    {
public static void SendEmail(String subject, String body, String emailTo, Attachment optionalAttachment)
        {
            Configuration configurationFile = WebConfigurationManager.OpenWebConfiguration("web.config");
            MailSettingsSectionGroup mailSettings = configurationFile.GetSectionGroup("system.net/mailSettings") as MailSettingsSectionGroup;
            SmtpClient smtp = new SmtpClient(mailSettings.Smtp.Network.Host);
            MailMessage email = new MailMessage();

            email.Subject = subject;
            email.From = new MailAddress("services@nyc.org");
            email.Body = body;
            email.IsBodyHtml = true;

            if (optionalAttachment != null)
            {
                email.Attachments.Add(optionalAttachment);
            }
           email.To=emailTo;
           smtp.Send(email);
        }
}

Open in new window

0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 12

Expert Comment

by:Jitendra Patil
Comment Utility
how are you storing your  uploaded files?
are your storing file in database or storing a path to file in database?

i think the file name seems to get wrong path, try with server.Mappath
try the link given below
Sending Email with attachment in ASP.NET using SMTP Server
hope this helps.
0
 

Author Comment

by:kqureshi321
Comment Utility
Hi ,
thank you for the response.
We have same code for dev website and it works. It was working on the live website until we use SSL. Any idea why it stopped?
0
 

Accepted Solution

by:
kqureshi321 earned 0 total points
Comment Utility
it fixed. One line of the code
FileCv.PostedFile.InputStream.Position=0; and everything is working
Thanks.
0
 

Author Closing Comment

by:kqureshi321
Comment Utility
we figured out the problem and it worked. As i mentioned, one line of code FileCv.PostedFile.InputStream.Position=0;
 and everything is working how it supposed to.
Thank you.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
In this video we show how to create a Distribution Group in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >>…
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now