Solved

Emails with blank attachments (PDF, DOC)

Posted on 2013-07-01
8
306 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
ID: 39291325
Are you facing this issue with all incomming emails (with attachement) or only emails coming from your application server?
0
 

Author Comment

by:kqureshi321
ID: 39291377
Only the emails from the application server.
0
 
LVL 27

Expert Comment

by:skullnobrains
ID: 39292246
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
Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

 

Author Comment

by:kqureshi321
ID: 39293131
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
 
LVL 12

Expert Comment

by:jitendra patil
ID: 39296482
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
ID: 39307517
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
ID: 39310542
it fixed. One line of the code
FileCv.PostedFile.InputStream.Position=0; and everything is working
Thanks.
0
 

Author Closing Comment

by:kqureshi321
ID: 39324385
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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 aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
A list of top three free exchange EDB viewers that helps the user to extract a mailbox from an unmounted .edb file and get a clear preview of all emails & other items with just a single click on mailboxes.
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
how to add IIS SMTP to handle application/Scanner relays into office 365.

840 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