Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have done already a simple email sending with attachment in C# and it works but it needs to reload the page. How can I do an email sending with attachment without reloading the page?

I have tried using jquery calling a controller from the view:

[$.post(url, {attachment : attachment }, function(data){}); ]

but i'm having problems with the URL and the restriction of browsers when I'm getting the file destination on the controller part.

is there another way to do this? without reloading the whole page for the attachment.

thanks!

What I have tried:

$.post(url, {attachment : attachment }, function(data){});

this returns null on the parameter of the controller.
Posted
Updated 22-Nov-16 18:04pm
v2
Comments
F-ES Sitecore 18-Nov-16 10:38am    
Google "ajax file upload" and you'll find lots of examples of how to do this.
jhayMe 18-Nov-16 18:23pm    
should i upload it first?
ZurdoDev 18-Nov-16 11:01am    
To send email you must run server side code so to do that without posting back you use jquery's ajax() method.
Er. Puneet Goel 22-Nov-16 3:24am    
Hey! Have you got the solution or still need some help ?
jhayMe 22-Nov-16 16:39pm    
still in need. Getting the file to controller is not a problem anymore but sending details from the view to controller with it ( such as email TO , email From, body of email, etc) is what I have problem with.

1 solution

C#
if (attachmentFilename != null)
{
    Attachment attachment = new Attachment(attachmentFilename, MediaTypeNames.Application.Octet);
    ContentDisposition disposition = attachment.ContentDisposition;
    disposition.CreationDate = File.GetCreationTime(attachmentFilename);
    disposition.ModificationDate = File.GetLastWriteTime(attachmentFilename);
    disposition.ReadDate = File.GetLastAccessTime(attachmentFilename);
    disposition.FileName = Path.GetFileName(attachmentFilename);
    disposition.Size = new FileInfo(attachmentFilename).Length;
    disposition.DispositionType = DispositionTypeNames.Attachment;
    message.Attachments.Add(attachment);                
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900