Not a Private Key

By Robert Ellison. Updated on Thursday, April 29, 2021.

When jarsigner says "Key Associated with [alias] not a private key" it almost certainly meant to say that you got your password wrong.

Add your comment...

Related Posts

(All Code Posts)

(Published to the Fediverse as: Not a Private Key #code #monodroid Check that you have the right password when jarsigner says Key Associated with alias not a private key. )

Sending email via GMail in C#/.NET using SmtpClient

By Robert Ellison. Updated on Friday, September 13, 2019.

Gmail Logo

Here’s a quick code snippet that configures SmtpClient to send email using Gmail’s SMTP server:

This can be frustratingly difficult to get right so I’ll run through each setting quickly.

DeliveryMethod: Set to SmtpDeliveryMethod.Network, the alternatives are copying the email to a directory for pickup by a different application. We want to connect directly to Gmail.

UseDefaultCredentials: False, as we’ll be providing our own credentials later. Setting properties in the right order is apparently important for SmtpClient, although the Microsoft documentation doesn’t mention this. Make sure you set UseDefaultCredentials to false before setting the Credentials property.

EnableSsl: True. SSL or TLS is required.

Host: smtp.gmail.com for this example. Note that this server restricts you to sending 2,000 emails per day. There is a less restrictive option for G Suite customers (smtp-relay.gmail.com) and a more restrictive server that can only send messages to Gmail or G Suite addresses (aspmx.l.google.com).

Port: Google says to use 465 for SSL and 587 for TLS. I’ve found that 587 with EnableSSL set to true works fine.

Credentials: Your Gmail address and password in a NetworkCredential. If your account has 2 step (multi factor) authentication then this won’t work. You can generate an app password easily and use this instead of your regular password. It’s also possible to use OAuth.

In the comments below Shika Helmy suggests also setting the Timeout property to 20000.

You can now use smtp.Send() to send the email.

Because it’s likely to be your personal account and there is a 2,000 message cap on sending I’d only recommend using this for small scale projects. You don’t want to get your Gmail account blocked. For higher volume I’d look at using SendGrid or similar.

One last note - while I’ve used SmtpClient for all sorts of trivial email needs over the years the latest Microsoft documentation marks it obsolete and warns:

SmtpClient and its network of types are poorly designed, we strongly recommend you use https://github.com/jstedfast/MailKit and https://github.com/jstedfast/MimeKit instead

Hope this expanded article helps. I still come back here periodically to cut and paste rather than mess up the property order again...

Add your comment...

Related Posts

(All Code Posts)

(Published to the Fediverse as: Sending email via GMail in C#/.NET using SmtpClient #code #smtp #email #google How to use the C# SmtpClient to send an email through the Gmail SMTP server (updated for two factor authentication). )

Twitter's API has got too painful for me

By Robert Ellison. Updated on Thursday, November 12, 2015.

Twitter's API has got too painful for me

I've developed a bunch of stupid, niche and vaguely promising apps on top of the Twitter API. During that time I've slogged through various painful and rapid shifts like changing IDs, authentication schemes and diktats handed down on which parts of the ecosystem Twitter would like to control. I've had to roll my own OAuth and even re-word a blog post to Twitter Support's satisfaction to get a blocked application unblocked again. It's been a pretty frustrating experience but worth rolling with the punches until the past week.

Twitter suspended Cleat, a tool for posting from the command line. So I emailed to ask why, too much effort for them to explain the rationale at the time they're putting the suspension in place I guess. I got an auto-response asking for information they must have already had and I replied to this. A few days later I still hadn't heard back so I emailed again and the ticket had been automatically closed. 

So far just the standard fuck-off-and-die support that you'd expect from a growing company that no longer wants to talk to it's users. But the auto-reply directed me to https://support.twitter.com/forms/ to file a new ticket. None of the options there relate to developers or a suspended application. I tried filing a ticket under 'deactivated account' which seemed the closest.

That form has a hard-coded 'With love,' valediction. Whoever thought that was cute should go through the process of trying to get help a few times. 

This attempt auto-responded to say that my account was not suspended, and would I like to fuck-off-and-die or got back to the forms center?

So I tried another form that actually seemed to submit but haven't heard anything back.

I'd be happy to update my software if I know which vague shifting facet of the Twitter terms of use I'd fallen foul of. Or at least I would have been. I'm just so sick of it that I've pulled Cleat and I'm done with any more personal projects that use the Twitter API. 

Add your comment...

Related Posts

(All Code Posts)

(Published to the Fediverse as: Twitter's API has got too painful for me #code #twitter #cleat #commandline #api Twitter's opaque API policies have led to me no longer developing on the platform. )

Catfood: Cleat 1.10

By Robert Ellison. Updated on Saturday, October 1, 2022.

I've just released an updated version of Cleat that supports geolocation and timestamps. Cleat is my Windows command line client for Twitter.

Add your comment...

Related Posts

(All Code Posts)

Catfood: PdfScan 1.40

By Robert Ellison. Updated on Wednesday, June 2, 2021.

Catfood: PdfScan 1.40

Catfood PdfScan 1.40 is a small bug fix release. PdfScan converts documents to PDFs with the help of a flatbed or automatic document feeder (ADF) scanner.

Add your comment...

Related Posts

(All Code Posts)

Upgrading to BlogEngine.NET 2.5

By Robert Ellison. Updated on Sunday, November 6, 2022.

Today I upgraded this blog to the latest and greatest version of BlogEngine.NET. Not entirely smooth sailing, so here are my notes for others (and the next time I have to do it):

The IsCommentsEnabled property BlogEngine.Core.Post has changed to HasCommentsEnabled. Not sure why this was worth changing but easy enough to fix.

BlogSettings.Instance.StorageLocation doesn't exist any more. After some digging it turns out that you need to use Blog.CurrentInstance.StorageLocation instead.

WidgetBase and WidgetEditBase in a couple of custom widgets complained that the type or namespace could not be found. This is fixed by adding a using statement for App_Code.Controls.

Updated 2012-03-11:

Getting the blog running locally was as usual only half the hassle. The next step is deploying to my hosting provider, Server Intellect. Things always start going wrong at this point. Luckily Server Intellect has some really great support staff and they respond quickly even on a Saturday night.

The first problem is that my backups were broken. Backups always succeed, restores always fail. After restoring my App_Data folder the last month of posts were missing. After digging for a bit it turned out that recent files were invisible over FTP but present in the control panel for the domain. My server had been migrated and some sort of permissions issue had broken access to new files. Not specifically a BlogEngine.net issue, but took a while to figure out and then for Server Intellect to fix.

Once the files were all there I uploaded and the blog itself was working fine, but the admin pages were screwy. It turns out that my server doesn't have ASP.NET MVC 3 installed. Server Intellect offered to migrate the server, but instead I copied System.Web.Mvc.dll to the Bin folder after finding a post on MVC 3 deployment from Scott Hanselman. I also needed to add a MIME type for .cshtml (text/html). With this in place the fancy new admin pages are up and running. 

Updated again, 2012-03-11:

Another namespace issue, ExtensionSettings in an extension doesn't resolve any more. Need to add a using statement for BlogEngine.Core.Web.Extensions. There are also some changes required to make an extension support multiple blogs.

Add your comment...

Related Posts

(All Code Posts)

Catfood.Shapefile 1.50

By Robert Ellison. Updated on Sunday, May 23, 2021.

I've just released a small update to my C# Shapefile library on Codeplex. Catfood.Shapefile 1.50 fixes a couple of bugs related to metadata and adds the ability to access metadata records directly via IDataRecord. 

Add your comment...

Related Posts

(All Code Posts)

Moon on a Wire

By Robert Ellison. Updated on Saturday, June 23, 2018.

Moon on a Wire

Testing posting by email with a picture of the moon from last night...

I've extended BlogEngine.NET to post by email. Not horrible for the very specific case of this blog and a short list of email clients. I shudder to think of extending it to the general emails and different templates.

Add your comment...

Related Posts

(All Code Posts)

(Published to the Fediverse as: Moon on a Wire #code #blogengine.net Picture of the Moon close to a wire. This is actually a test of posting by email from blogengine.net. )

Catfood.Shapefile 1.40

By Robert Ellison. Updated on Monday, September 19, 2022.

I’ve just released a small update to Catfood.Shapefile. Stephan Stapel, who implemented PolyLineM support, has contributed a patch that improves the class hierarchy. CodePlex user originSH suggested supporting the ACE driver for 64-bit systems. I’ve added a constructor overload that allows you to use predefined Jet and ACE connection strings or provide your own templates if necessary. Thanks to Stephan and originSH.

Catfood.Shapefile is a .NET library for enumerating ESRI shapefiles. I originally wrote the library to help me build some complex layers in Catfood Earth. Since then it’s picked up thousands of users and some really valuable suggestions and patches from the CodePlex community. I’m very glad a took a couple of hours to open source the library back in 2009.

Add your comment...

Related Posts

(All Code Posts)

Catfood: Cleat

By Robert Ellison. Updated on Saturday, October 1, 2022.