[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Emails with blank attachments (PDF, DOC)

Posted on 2013-07-01
8
Medium Priority
?
327 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:Galina Besselyanova
[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:Galina Besselyanova
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
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 

Author Comment

by:Galina Besselyanova
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:Galina Besselyanova
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:
Galina Besselyanova 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:Galina Besselyanova
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A couple of months ago we ran into an issue that necessitated re-creating our Edge Subscriptions. However, when we attempted to execute the command: New-EdgeSubscription -filename C:\NewEdgeSub_01.xml we received an error indicating that the LDAP se…
Know the reasons and solutions to move/import EDB to New Exchange Server. Also, find out how to recover an Exchange .edb file and to restore the file back.
In this video we show how to create a Contact 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 >> Contact ta…
how to add IIS SMTP to handle application/Scanner relays into office 365.

650 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