Link to home
Start Free TrialLog in
Avatar of wolfcoop
wolfcoop

asked on

Can you fire a mailto: href from VB.NET code behind. I can create it, assign the email, just cant get it to fire automatically without a client click

I am trying to fire a mailto href in the code behind file, so that once the database update is finished it pulles up an email client window with the Email address populated.  The click event of the button drives thedb update, and then I do not want another click from my user, but to fire the mailto href automatically.  Below is my code.  What renders the href?  Would I do response.write or something to get it to fire???  Help please.  Thanks.  Below is my code which is golden up till firing the html anchor.
Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
        Dim strLeadID As String = Request.QueryString("LeadID")
        Dim datDate As Date = Now()
        Dim DBCon As SqlConnection = New SqlConnection()
        Dim Command As SqlCommand = New SqlCommand()
        Dim LeadCaller As DropDownList = form1.FindControl("WebPartManager1$gwptblformatting$frmAppBorInfo$ddLeadCallers")
        Dim strCallerID = LeadCaller.SelectedValue
        'MsgBox(strCallerID)
        DBCon.ConnectionString = ConfigurationManager.ConnectionStrings("VACRMDEVConnectionString").ConnectionString
        Command.CommandText = _
        "Insert Into ConvLog LeadID = " + strLeadID + ", Conversation = 3, Result = 1, NoteDate = " + datDate + ""
        Command.CommandType = CommandType.Text
        Command.Connection = DBCon
        DBCon.Open()
        Command.ExecuteNonQuery()
        DBCon.Close()
 
        'MsgBox("Here Dude")
        Dim Address As TextBox = form1.FindControl("WebPartManager1$gwptblformatting$frmAppBorInfo$Email")
        Dim strEmail As String = Address.Text
        Dim anch As New HtmlAnchor
        anch.HRef = "mailto:" + strEmail + ""
 
 
 
    End Sub

Open in new window

Avatar of debuggerau
debuggerau
Flag of Australia image

Is Outlook the one prompting for your acceptance to sent the email?
Outlook has a security 'feature' recently updated to prevent unauthorized use of your account.
OnClick is a product I have used to overcome it..
Avatar of wolfcoop
wolfcoop

ASKER

No.  I dont get a window at all.  First it was just an image that fired off a mailto hyperlkink from a list of leads.  Now my boss wants me to update the database before I fire off the email window.  My code executes, does the database update, and creates the mailto hyperlink, I just want to fire it automatically so that it appears to the end user that they have just clicked a mailto hyperlink.  In other words it pulls up the outlook new message window, with the email address pre-populated.  I just need to htmlanchor.fire or htmlanchor.execute or some way to execute the mailto hyperlink from the code behind file.  I know this is executing on the server, so can I do a response.write"execute hyperlink" or am I just barking up the wrong tree.  I changed my image to an image button so I would have the onclick event available.  Is their an easier way to fire off an outlook email?
Avatar of Göran Andersson
If you would use a hyperlink, then you would have to put it in the page, and then add some Javascript to the page that would simulate a click on the link...

Skip the hyperlink and just redirect to the url:

Response.Redirect("mailto:" + strEmail)
tried that, but I do not want to leave the page clicked on.  I know the solution, its just have to import.

Imports System.Web.Mail

and create it and send it from the server.  lol.  Thats the easiest way to handle it, and then I can actually log whethr the user actuall sends the email from server logs.  thanks for your help though.  thought thiswas going to be easy.  It never is.  lol.  Thanks again.
I thought that you wanted the mail to be sent by the mail program, so that the user could write something in it or attach something to it. That was what you specifically asked for, otherwise I would of course suggested sending it from the server...
I do, and now I had not thought that through.  Was eating dinner.  I do need the user to be able to type the body, etc.  So I can either trap that info in a web form input boxes, or dink with this some more, which I will do.  If I can target a new window with response.redirect that would solve it.
ASKER CERTIFIED SOLUTION
Avatar of Göran Andersson
Göran Andersson
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Forced accept.

Computer101
EE Admin