Solved

Emails with blank attachments (PDF, DOC)

Posted on 2013-07-01
8
314 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

 

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 13

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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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.
To show how to create a transport rule 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 Mail Flow >> Rules tab.:  To cr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

688 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