• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2970
  • Last Modified:

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
        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
        '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

1 Solution
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..
wolfcoopAuthor Commented:
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?
Göran AnderssonCommented:
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)
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

wolfcoopAuthor Commented:
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.
Göran AnderssonCommented:
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...
wolfcoopAuthor Commented:
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.
Göran AnderssonCommented:
> If I can target a new window with response.redirect that would solve it.

At the time of redirecting, it's already too late to decide where the response should go. That's determined when the request is sent, so you would have to set the target before the form is posted.

Sending the mail from the server sounds like a better idea, as that doesn't require a mail program to be installer and configured on the client computer. If you want the user to be able to put text in the mail, that is easily done with input box(es). Attaching files can even be done by letting the user upload the files to the server, and put those as attachments in the mail.
Forced accept.

EE Admin

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now