0

I have the following options

  1. Using System.Net.Mail namespace and send mail through SMTPClient
  2. Connecting to Outlook specifically and adding attachment
  3. Using 'MailTo' function in javascript, which does not add 'Attachment'

But none of them are apt for my requirement, where I need to add an attachment to the Default mail client on the user's system.

Is there any way to do that?

MailTo Option- Can I add attachment to this?

<asp:Button ID="btnSend" Text="Send" runat="server" onClientclick="OpenMail()" />

<script type="text/javascript" language="javascript">
function OpenMail()
{    
location.href='mailto:dummy@gmail.com?subject=Message Title&body=Message Content';   
}
</script>
Thom Smith
  • 13,916
  • 6
  • 45
  • 91
user1208862
  • 303
  • 3
  • 7
  • 19
  • What code sample do you currently have that you can show us..? also this is very simple if you care to venture out to the land of the World Wide Web, there are 1000's of examples on how to do this.. especially with C# – MethodMan Oct 30 '12 at 13:38
  • I need to add an attachment to the default mail client, like outlook or any other mailing service. I am able to add subject, body but not attachment. – user1208862 Oct 30 '12 at 13:49
  • Is the file on the client or the server? Since `mailto:` is purely client-side how do you intend to send the file to the client if it's on the server? – D Stanley Oct 30 '12 at 13:50
  • possible duplicate of [Attach File Through mailto URI](http://stackoverflow.com/questions/2372036/attach-file-through-mailto-uri) – Andreas Louv Oct 30 '12 at 13:50
  • @user1208862 not posible to use attachment in `mailto:` – Andreas Louv Oct 30 '12 at 13:55
  • Ok,Is there any other way to attach a file to the Default mail Client in the user system? – user1208862 Oct 30 '12 at 13:56
  • My requirement is like, As soon a user clicks a button, the default mail client should be opened with the information like Email address, Subject, Body, Attachment. Any Ideas? – user1208862 Oct 30 '12 at 13:58

1 Answers1

0

If the file is on the server then you can't use the client's email program to automatically send it as an an attachment. Some alternatives:

  1. Have the client fill out an "email form" (from, to, message, etc.) and send from the server using SMTPClient

  2. Send using mailto: tags with a link to the file within the email body

If you try to have the user download the file then send using mailto: there are too many opportunities for the link to be broken. You don't know where the file will be downloaded to, if the user changes the name, etc.

Why is using the client's email program a hard requirement?

D Stanley
  • 149,601
  • 11
  • 178
  • 240
  • I have already checked out the 1st Option. It doesnt fit the requirement. The requirement is to use a default mail client, not sending the mail from the Web Page. – user1208862 Oct 30 '12 at 14:35
  • The 2nd Option, i.e sending the link of the file within the Email body doesnt show as attachment in the Generated Mail.. – user1208862 Oct 30 '12 at 14:37
  • @user1208862 You can't send a file from the server using the client's email program without the user downloading the file first. And you can't guarantee that the file is saved to a specific location with a specific name. The user will have the ability to change both of those from the browser. – D Stanley Oct 30 '12 at 14:53
  • @user1208862 Regarding your second comment - Because it's not an attachment, it would be a hyperlink that the recipient could use to get the file off of the server site. – D Stanley Oct 30 '12 at 14:54