使用 javascript 打开 Outlook 以在 C# 中发送带有附件的邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12247696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open outlook with javascript for sending mail with attachment in c#
提问by user1102001
i am using javascript for open default mail client in asp.net c# web application. below is my code..
我正在使用 javascript 在 asp.net c# web 应用程序中打开默认邮件客户端。下面是我的代码..
<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??
这工作正常,但在我的情况下,我想从服务器端代码获取附件文件路径,因为我想将水晶报告作为附件发送。我将如何从服务器端获得该路径?
回答by NoNaMe
check the link opening Outlook through javascriptOR/And This oneYou can try this part of code
检查通过javascript打开Outlook的链接或/和这个你可以试试这部分代码
function sendMail(){
location.href = "mailto:[email protected]?subject=Feedback for
webdevelopersnotes.com&body=The Tips and Tricks section is
great";
}