Open outlook with javascript for sending mail with attachment in c# - Stack Overflow

i am using javascript for open default mail client in asp c# web application.below is my code..<scr

i am using javascript for open default mail client in asp c# web application. below is my code..

<script language="javascript">
function SendAttach() {
    var theApp  //Reference to Outlook.Application 
    var theMailItem //Outlook.mailItem
    //Attach Files to the email
    var attach3 = "c:\\mail\\test.txt"
    //Construct the Email including To(address),subject,body
    //var recipient
    var subject = "Email Using JavaScript"
    var msg = "This is a test mail,sent to you using javascript by kushan thakershy"
    //Create a object of Outlook.Application
    try {
        var theApp = new ActiveXObject("Outlook.Application");
        var objNS = theApp.GetNameSpace('MAPI');
        var theMailItem = theApp.CreateItem(0) // value 0 = MailItem
        //Bind the variables with the email
        theMailItem.to = "[email protected]"
        theMailItem.Subject = (subject);
        theMailItem.Body = (msg);
        theMailItem.Attachments.add(attach3);
        theMailItem.display();

        //Show the mail before sending for review purpose
        //You can directly use the theMailItem.send() function
        //if you do not want to show the message.

    }
    catch (err) {
        alert("The following may have cause this error: \n" +
 "1. The Outlook express 2003 is not installed on the machine.\n" +
 "2. The msoutl.olb is not availabe at the location " +
 "C:\\Program Files\\Microsoft Office\\OFFICE11\\msoutl.old on client's machine " +
 "due to bad installation of the office 2003." +
 "Re-Install office2003 with default settings.\n" +
 "3. The Initialize and Scripts ActiveX controls not marked as safe is not set to enable.")
        document.write("<a href=\"" + "./testemail.asp" + "\"" + ">" + "Go Back" + "</a>")
    }

}

this is working fine but in my case i want to get attachment file path from server side code because i want to send crystal report as attachment. how will i get that path from server side??

i am using javascript for open default mail client in asp c# web application. below is my code..

<script language="javascript">
function SendAttach() {
    var theApp  //Reference to Outlook.Application 
    var theMailItem //Outlook.mailItem
    //Attach Files to the email
    var attach3 = "c:\\mail\\test.txt"
    //Construct the Email including To(address),subject,body
    //var recipient
    var subject = "Email Using JavaScript"
    var msg = "This is a test mail,sent to you using javascript by kushan thakershy"
    //Create a object of Outlook.Application
    try {
        var theApp = new ActiveXObject("Outlook.Application");
        var objNS = theApp.GetNameSpace('MAPI');
        var theMailItem = theApp.CreateItem(0) // value 0 = MailItem
        //Bind the variables with the email
        theMailItem.to = "[email protected]"
        theMailItem.Subject = (subject);
        theMailItem.Body = (msg);
        theMailItem.Attachments.add(attach3);
        theMailItem.display();

        //Show the mail before sending for review purpose
        //You can directly use the theMailItem.send() function
        //if you do not want to show the message.

    }
    catch (err) {
        alert("The following may have cause this error: \n" +
 "1. The Outlook express 2003 is not installed on the machine.\n" +
 "2. The msoutl.olb is not availabe at the location " +
 "C:\\Program Files\\Microsoft Office\\OFFICE11\\msoutl.old on client's machine " +
 "due to bad installation of the office 2003." +
 "Re-Install office2003 with default settings.\n" +
 "3. The Initialize and Scripts ActiveX controls not marked as safe is not set to enable.")
        document.write("<a href=\"" + "./testemail.asp" + "\"" + ">" + "Go Back" + "</a>")
    }

}

this is working fine but in my case i want to get attachment file path from server side code because i want to send crystal report as attachment. how will i get that path from server side??

Share Improve this question asked Sep 3, 2012 at 12:14 user1102001user1102001 7072 gold badges10 silver badges21 bronze badges 3
  • possible duplicate of opening Outlook through javascript – Donal Fellows Commented Nov 30, 2012 at 9:25
  • @DonalFellows Despite its title, the other question is ActiveX – rds Commented Jan 11, 2013 at 16:35
  • Please specify "ServerSide Report" in more details.... you mean Crystal report .rpt file or want to attach a generated report from crystal report(in desired format .doc / .xls / .pdf)? – MarmiK Commented Jul 16, 2014 at 9:03
Add a ment  | 

1 Answer 1

Reset to default 0

check the link opening Outlook through javascript OR/And This one You can try this part of code

function sendMail(){

location.href = "mailto:[email protected]?subject=Feedback for 
webdevelopersnotes.&body=The Tips and Tricks section is 
great";




}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745080056a4610069.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信