Solved

Emails with blank attachments (PDF, DOC)

Posted on 2013-07-01
8
302 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 26

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
 

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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
We are happy to announce a brand new addition to our line of acclaimed email signature management products – CodeTwo Email Signatures for Office 365.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

920 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

15 Experts available now in Live!

Get 1:1 Help Now