Elsinore

User Forum

www.screenconnect.com
Welcome Guest Search | Active Topics | Log In | Register

Tag as favorite
programmatic Create Email Link Session
computerhelpsos
#1 Posted : Wednesday, February 08, 2012 5:21:06 AM
Rank: Newbie
Joined: 2/8/2012
Posts: 5
Location: Alexandria,VA
Here is the ashx file. Here is what I have so far. but it is not working yet. Please advise. Thanks andy
Quote:

<%@ WebHandler Language="C#" Class="CreateSession" %>

using System;
using System.Net.Mail;
using System.Web;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using Elsinore.ScreenConnect;
using SmtpClient = Elsinore.ScreenConnect.SmtpClient;


public class CreateSession : IHttpHandler
{
private string sessionCode = "Email "+DateTime.Now;

object CreateEmail(string overrideFrom, string to, string subjectFormat, string bodyFormat, bool isBodyHtml, bool send, string overrideRelayHost, params object[] formatParams)
{
var mailMessage = new MailMessage();

if (overrideFrom != null)
mailMessage.From = new MailAddress(overrideFrom);

mailMessage.To.Add(to);
mailMessage.Subject = string.Format(subjectFormat, formatParams);
mailMessage.Body = string.Format(bodyFormat, formatParams);
mailMessage.IsBodyHtml = isBodyHtml;

if (send)
{
var client = new SmtpClient();

if (overrideRelayHost != null)
client.Host = overrideRelayHost;

client.Send(mailMessage);
}

return new { sent = send, from = mailMessage.From.Address, to = mailMessage.To[0].Address, subject = mailMessage.Subject, body = mailMessage.Body };
}
public object CreateSessionEmail(Guid sessionID)
{
Permissions.AssertPermission(new PermissionRequest { Name = PermissionInfo.CreateAttendedSessionPermission }, true);

using (var sessionManager = ServiceChannelPool<ISessionManagerChannel>.Instance.Borrow())
{
var sessionSummary = sessionManager.GetSessionSummary(sessionID);
var webServerUri = ServerExtensions.GetWebServerUri(ConfigurationManager.AppSettings, HttpContext.Current.Request.Url, true, false);
var sessionGuestUrl = Extensions.EncodeUrl(webServerUri.Uri.AbsoluteUri, ServerConstants.SessionIDParameterName, sessionSummary.SessionID);
var send = !Convert.ToBoolean(ConfigurationManager.AppSettings[ServerConstants.SmtpUseClientSettingsKey]);
var isBodyHtml = Convert.ToBoolean(global::Resources.Default.CreateSessionPanel_EmailBodyIsHtml);

return this.CreateEmail(null, sessionSummary.Tag, global::Resources.Default.CreateSessionPanel_EmailSubject, global::Resources.Default.CreateSessionPanel_EmailBody, isBodyHtml, send, null, sessionSummary.Host, sessionGuestUrl);
}
}

public void ProcessRequest(HttpContext context)
{
var Email = context.Request.QueryString["Email"];

using (var sessionManager = ServiceChannelPool<ISessionManagerChannel>.Instance.Borrow())
{
var session = sessionManager.CreateSession(InvitationType.Email, sessionCode,Email );
CreateSessionEmail(session.SessionID);

context.Response.Redirect("Guest.aspx");
}

}

public bool IsReusable
{
get { throw new NotImplementedException(); }
}

//window.invokeService("CreateSessionEmail", [sessionID], function (email) { window.trySendClientEmail(email); };

//window.refresh(true, autoJoin ? sessionID : null);
//}


//public bool IsReusable { get { return false; } }
}
Jake Morgan
#2 Posted : Thursday, February 09, 2012 12:40:36 AM
Rank: Administration
Joined: 4/9/2010
Posts: 871
What about it isn't working? Are you getting an error? Can you put in some tracing to see what the issue is?
computerhelpsos
#3 Posted : Thursday, February 09, 2012 6:38:34 AM
Rank: Newbie
Joined: 2/8/2012
Posts: 5
Location: Alexandria,VA
Quote:
Stack Trace:

[FormatException: The specified e-mail address is currently not supported.]
System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32& offset, String& displayName) +1432
System.Net.Mail.MailAddressCollection.ParseValue(String addresses) +82
CreateSession.CreateEmail(String overrideFrom, String to, String subjectFormat, String bodyFormat, Boolean isBodyHtml, Boolean send, String overrideRelayHost, Object[] formatParams) +114
CreateSession.CreateSessionEmail(Guid sessionID) +534
CreateSession.ProcessRequest(HttpContext context) +197
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +586
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +177
Jake Morgan
#4 Posted : Thursday, February 09, 2012 2:20:07 PM
Rank: Administration
Joined: 4/9/2010
Posts: 871
It apparently doesn't like the format of your email address.
computerhelpsos
#5 Posted : Friday, February 10, 2012 4:29:29 AM
Rank: Newbie
Joined: 2/8/2012
Posts: 5
Location: Alexandria,VA
If I am logged in the http://www.computerhelpsos.com:8040/AutoHostEmail.ashx/?Email=xxx@yahoo.com works now. But if I am not logged in (and I should not be logged in) I get the following Trace:
Quote:

[SecurityException: Needs permission.]
Elsinore.ScreenConnect.Permissions.AssertPermission(PermissionRequest request, IEnumerable`1 entries, Boolean throwOrEnd) +156
CreateSession.CreateSessionEmail(Guid sessionID, String xEmail) +114
CreateSession.ProcessRequest(HttpContext context) +196
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +586
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +177


Here is the full code so far, the response redirect is also not working yet.
Quote:


<%@ WebHandler Language="C#" Class="CreateSession" %>

using System;
using System.Net.Mail;
using System.Web;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using Elsinore.ScreenConnect;
using SmtpClient = Elsinore.ScreenConnect.SmtpClient;


public class CreateSession : IHttpHandler
{
private string sessionCode = "Email "+DateTime.Now;

object CreateEmail(string overrideFrom, string to, string subjectFormat, string bodyFormat, bool isBodyHtml, bool send, string overrideRelayHost, params object[] formatParams)
{

var mailMessage = new MailMessage();
//to = "computerhelpsos@gmail.com";
if (overrideFrom != null)
mailMessage.From = new MailAddress(overrideFrom);

mailMessage.To.Add(to);
mailMessage.Subject = string.Format(subjectFormat, formatParams);
mailMessage.Body = string.Format(bodyFormat, formatParams);
mailMessage.IsBodyHtml = isBodyHtml;

if (send)
{
var client = new SmtpClient();

if (overrideRelayHost != null)
client.Host = overrideRelayHost;

client.Send(mailMessage);

}

return new { sent = send, from = mailMessage.From.Address, to = mailMessage.To[0].Address, subject = mailMessage.Subject, body = mailMessage.Body };
}
public object CreateSessionEmail(Guid sessionID,string xEmail)
{
Permissions.AssertPermission(new PermissionRequest { Name = PermissionInfo.CreateAttendedSessionPermission }, true);

using (var sessionManager = ServiceChannelPool<ISessionManagerChannel>.Instance.Borrow())
{
var sessionSummary = sessionManager.GetSessionSummary(sessionID);
var webServerUri = ServerExtensions.GetWebServerUri(ConfigurationManager.AppSettings, HttpContext.Current.Request.Url, true, false);
var sessionGuestUrl = Extensions.EncodeUrl(webServerUri.Uri.AbsoluteUri, ServerConstants.SessionIDParameterName, sessionSummary.SessionID);
var send = !Convert.ToBoolean(ConfigurationManager.AppSettings[ServerConstants.SmtpUseClientSettingsKey]);
var isBodyHtml = Convert.ToBoolean(global::Resources.Default.CreateSessionPanel_EmailBodyIsHtml);

return this.CreateEmail(null, xEmail, global::Resources.Default.CreateSessionPanel_EmailSubject, global::Resources.Default.CreateSessionPanel_EmailBody, isBodyHtml, send, null, sessionSummary.Host, sessionGuestUrl);
}
}

public void ProcessRequest(HttpContext context)
{

var email = context.Request.QueryString["Email"];
//context.Response.Redirect("Guest.aspx");
using (var sessionManager = ServiceChannelPool<ISessionManagerChannel>.Instance.Borrow())
{
var session = sessionManager.CreateSession(InvitationType.Email, sessionCode,email );

CreateSessionEmail(session.SessionID,email);

context.Server.TransferRequest("Guest.aspx");
}

}

public bool IsReusable
{
get { throw new NotImplementedException(); }
}


}
Jake Morgan
#6 Posted : Friday, February 10, 2012 10:51:25 PM
Rank: Administration
Joined: 4/9/2010
Posts: 871
Pass "false" instead of "true" here:

Code:
Permissions.AssertPermission(new PermissionRequest { Name = PermissionInfo.CreateAttendedSessionPermission }, true);
computerhelpsos
#7 Posted : Friday, February 10, 2012 11:36:44 PM
Rank: Newbie
Joined: 2/8/2012
Posts: 5
Location: Alexandria,VA
Still gettting a permission error msg with see below changed to false.

Quote:
Permissions.AssertPermission(new PermissionRequest { Name = PermissionInfo.CreateAttendedSessionPermission },false);


Quote:
Stack Trace:

[SecurityException: Needs permission.]
Elsinore.ScreenConnect.Permissions.AssertPermission(PermissionRequest request, IEnumerable`1 entries, Boolean throwOrEnd) +156
CreateSession.CreateSessionEmail(Guid sessionID, String xEmail) +114
CreateSession.ProcessRequest(HttpContext context) +196
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +586
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +177
Jake Morgan
#8 Posted : Friday, February 24, 2012 3:17:12 PM
Rank: Administration
Joined: 4/9/2010
Posts: 871
I'm not sure how you'd be getting that error. The last parameter "throwOrEnd" being set to false would indicate "end", which should sent a 401 unauthorized. Are you sure you've saved the file?
computerhelpsos
#9 Posted : Monday, March 05, 2012 9:49:03 PM
Rank: Newbie
Joined: 2/8/2012
Posts: 5
Location: Alexandria,VA
Quote:
here is the final autohostemail.ashx/?Email=customer@customerland.com

Quote:
works 100 percent

Quote:
please be aware of what has been commented out

Quote:


<%@ WebHandler Language="C#" Class="CreateSession" %>

using System;
using System.Net.Mail;
using System.Web;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using Elsinore.ScreenConnect;
using SmtpClient = Elsinore.ScreenConnect.SmtpClient;


public class CreateSession : IHttpHandler
{
private string sessionCode = "Auto "+DateTime.Now;

public object CreateSessionEmail(Guid sessionID, string xEmail)
{
//Permissions.AssertPermission(new PermissionRequest { Name = PermissionInfo.CreateAttendedSessionPermission }, false);

using (var sessionManager = ServiceChannelPool<ISessionManagerChannel>.Instance.Borrow())
{
var sessionSummary = sessionManager.GetSessionSummary(sessionID);
var webServerUri = ServerExtensions.GetWebServerUri(ConfigurationManager.AppSettings, HttpContext.Current.Request.Url, true, false);
var sessionGuestUrl = Extensions.EncodeUrl(webServerUri.Uri.AbsoluteUri, ServerConstants.SessionIDParameterName, sessionSummary.SessionID);
var send = !Convert.ToBoolean(ConfigurationManager.AppSettings[ServerConstants.SmtpUseClientSettingsKey]);
var isBodyHtml = Convert.ToBoolean(global::Resources.Default.CreateSessionPanel_EmailBodyIsHtml);

return this.CreateEmail(null, xEmail, global::Resources.Default.CreateSessionPanel_EmailSubject, global::Resources.Default.CreateSessionPanel_EmailBody, isBodyHtml, send, null, sessionSummary.Host, sessionGuestUrl);
}
}
object CreateEmail(string overrideFrom, string to, string subjectFormat, string bodyFormat, bool isBodyHtml, bool send, string overrideRelayHost, params object[] formatParams)
{

var mailMessage = new MailMessage();
//to = "computerhelpsos@gmail.com";
if (overrideFrom != null)
mailMessage.From = new MailAddress(overrideFrom);

mailMessage.To.Add(to);
mailMessage.Subject = string.Format(subjectFormat, formatParams);
mailMessage.Body = string.Format(bodyFormat, formatParams);
mailMessage.IsBodyHtml = isBodyHtml;

if (send)
{
var client = new SmtpClient();

if (overrideRelayHost != null)
client.Host = overrideRelayHost;

client.Send(mailMessage);

}

return new { sent = send, from = mailMessage.From.Address, to = mailMessage.To[0].Address, subject = mailMessage.Subject, body = mailMessage.Body };
}
public void ProcessRequest(HttpContext context)
{

var email = context.Request.QueryString["Email"];
using (var sessionManager = ServiceChannelPool<ISessionManagerChannel>.Instance.Borrow())
{
var session = sessionManager.CreateSession(InvitationType.Email, email, "Auto");
CreateSessionEmail(session.SessionID, email);
context.Response.Redirect("Guest.aspx");
}


}

public bool IsReusable { get { return false; } }
}
wimmme
#10 Posted : Wednesday, May 16, 2012 10:58:31 AM
Rank: Newbie
Joined: 5/16/2012
Posts: 5
Location: Belgium
this works like a charm !

Any idea how I could complete this with an automatic login ?
I create the session as a user for a certain email adres, but then I need to login. For our customerservice it would be very practical to NOT have to log in.
Can I automate a login for a certain user ?

Big thanx in advance !
Jake Morgan
#11 Posted : Wednesday, May 16, 2012 7:12:27 PM
Rank: Administration
Joined: 4/9/2010
Posts: 871
Why not just comment out this line like in the previous post?:

Permissions.AssertPermission(new PermissionRequest { Name = PermissionInfo.CreateAttendedSessionPermission }, true);
wimmme
#12 Posted : Friday, May 18, 2012 9:43:18 AM
Rank: Newbie
Joined: 5/16/2012
Posts: 5
Location: Belgium
Jake Morgan wrote:
Why not just comment out this line like in the previous post?:

Permissions.AssertPermission(new PermissionRequest { Name = PermissionInfo.CreateAttendedSessionPermission }, true);


Jake, tnx for the reply. I did comment out that line. So it creates me a session for a certain email-address, en then redirects me to the Guest page where I have to logon.
What I would like to do is create the session for a certain email address, and the redirect me to the the host page "without logging in" !

Our screenconnect is installed on our webserver, which is in the DMZ an NOT in our domain, so integrated authentication is not an option I guess ?
We have a common user for sc which should be used by everyone at our company, with a complex pwd so not the whole world can log in and crreate or takeover sessions, but I would like to avoind to have everyone remember yet another complex pwd ...

Maybe asking too much ?

Or would it be possible to automate the forms login anyhow ?
So auto create email session -> auto login -> view sessions.
Or Auto login -> auto create email session -> view session ?

Big tnx in advance !
Jake Morgan
#13 Posted : Friday, May 18, 2012 1:40:27 PM
Rank: Administration
Joined: 4/9/2010
Posts: 871
You can automate the forms login. Look in setupwizard.aspx for where we set the auth cookie and put that in your page
1 user thanked Jake Morgan for this useful post.
wimmme on 5/18/2012
Jake Morgan
#14 Posted : Friday, May 18, 2012 3:02:02 PM
Rank: Administration
Joined: 4/9/2010
Posts: 871
This is the line you'd need:

Code:
FormsAuthentication.SetAuthCookie(userName, true);


And you could just hardcode your user:

Code:
FormsAuthentication.SetAuthCookie("MyUser", true);

1 user thanked Jake Morgan for this useful post.
wimmme on 5/18/2012
wimmme
#15 Posted : Friday, May 18, 2012 3:08:24 PM
Rank: Newbie
Joined: 5/16/2012
Posts: 5
Location: Belgium
Jake Morgan wrote:
This is the line you'd need:

Code:
FormsAuthentication.SetAuthCookie(userName, true);


And you could just hardcode your user:

Code:
FormsAuthentication.SetAuthCookie("MyUser", true);



I just completed this, and it works, thank you for the support !

To be complete, you also need to include:

Code:
using System.Web.Security;


This is why I already made clear I really wanted ScreenConnect instead of the already inhouse (other office) TeamViewer.

I love the Business model, the ease of use, the support, the forum, ...


Keep up the good work ! I'll recommend SC to everyone who needs a tool like this ....
Users browsing this topic
Guest
Tag as favorite
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.