Tweet button / link without javascript – HTML only

Twitter buttonIf you’ve ever wanted to include a ‘Tweet’ button or link but didn’t want to use the popular Tweet Button code from Twitter (it uses a remote javascript function), there is an alternate approved method called “Intents”. This function works great for instances when simple HTML is preferred (emails, pages geared toward older or simple browsers, etc.). However it doesn’t provide extras like showing how many have used the button or creating the image automatically. So how does it work?

Using Twitter’s Web Intents, you can create links like below:

<a href="http://twitter.com/intent/tweet?url=http://chrisbitting.com
&text=Checkout this awesome blog.&via=chrisbitting&hashtags=twitter"
 title="Tweet" target="_blank">Tweet</a>

Which looks like: Tweet

No Javascript!

Be sure to check the documentation for more options and details: https://dev.twitter.com/docs/intents

Tweet button / link without javascript – HTML only

Adding attachments to an email using Exchange Web Services

In a previous article on sending email with Exchange Web Services (EWS) we showed how easy it was to integrate with Exchange and send email. If you’ve ever wanted to attach a file to an email that your sending, it’s super easy (much faster than the System.Net.Mail method):

//Create an email message and identify the Exchange service
EmailMessage message = new EmailMessage(service);

//Attach a file - THE MAGIC
message.Attachments.AddFileAttachment(@"c:\temp\somefile.jpg");

//Send the email message and save a copy
message.SendAndSaveCopy();

That’s it! If you want to see all of the code needed for sending, see Retrieving and Sending Email using Exchange Web Services Managed API 2.0 (c#)

Adding attachments to an email using Exchange Web Services

c# Get Email Address from Active Directory (using Username) in Asp.net

dirSometimes it’s handy to grab either a username or email address (why not both?) from active directory. Below are the steps I believe you’ll need to get going quickly. In my example, I’m using VS2012 and .net 4.5.

1. Set your app to use windows authentication, you’ll need to set these to debug in VS:

Your web.config:

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <authentication mode="Windows" />
    <identity impersonate="true" />

    <authorization>
      <allow users="*" />
    </authorization>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>
</configuration>

Your project settings:

vs_winauth

2. Now in your application, add a reference to System.DirectoryServices:

dirservices

3. And in your code file:

using System.DirectoryServices;

4. A little function to search through active directory:

 private string uEmail(string uid)
        {
            DirectorySearcher dirSearcher = new DirectorySearcher();
            DirectoryEntry entry = new DirectoryEntry(dirSearcher.SearchRoot.Path);
            dirSearcher.Filter = "(&(objectClass=user)(objectcategory=person)(mail=" + uid + "*))";

            SearchResult srEmail = dirSearcher.FindOne();

            string propName = "mail";
            ResultPropertyValueCollection valColl = srEmail.Properties[propName];
            try
            {
                return valColl[0].ToString();
            }
            catch
            {
                return "";
            }

        }

5. And finally, how you can use:

string uName = "";
uName = uEmail(HttpContext.Current.User.Identity.Name.Replace(@"yourdomain\", ""));

Hope you enjoy! You can also use this method to retrieve other AD details (groups, full name, etc.).

c# Get Email Address from Active Directory (using Username) in Asp.net

.net SMTP – Sending An Email Message With A Display Name

email-blueIf you’ve ever used .net to send email messages (and I hope you have!) you may have wanted to send the message from or to not only an address, but also include a name. The ‘display name’ is the name that appears in many email clients instead of the address (think ‘Chris Bitting’ instead of ‘cbitting@something.com’). .Net honors the email standard of “Display Name <email@domain.com>”.

Below is a quick example on how this looks in vb.net:

Dim mail As New System.Net.Mail.MailMessage("""Some Body"" <person@company.com>", """A Different Person"" <person2@company2.com>", "Subject", "Body")

Below is a full example on an email function (include Imports System.Net.Mail): Continue reading “.net SMTP – Sending An Email Message With A Display Name”

.net SMTP – Sending An Email Message With A Display Name

Retrieving and Sending Email using Exchange Web Services Managed API 2.0 (c#)

exlogoIf you haven’t already had the need, I’m sure you will at some point, to either retrieve email or send email through Exchange (not just relay or connect to Outlook) using .net. Since Microsoft introduced the Microsoft Exchange Web Services Managed API 2.0 this task has become much more efficient No more clunky 2.0 type web service references etc. Below is a complete chuck of code with a few samples. One sample function sends an email, the other retrieves email messages from an inbox with the option of filters.

Continue reading “Retrieving and Sending Email using Exchange Web Services Managed API 2.0 (c#)”

Retrieving and Sending Email using Exchange Web Services Managed API 2.0 (c#)