SyntaxHighlighter

Showing posts with label mail. Show all posts
Showing posts with label mail. Show all posts

Friday, 7 December 2012

UTF8 / Unicoding Body of PHP PEAR Email

Further to the previous article I wrote about unicoding an email subject in PHP, I was getting issues with the body not UTF8 encoding correctly either. When I used the Mail_mime object (as I was sending attachements), the standard Content-Type of text/html; charset=utf-8 in the headers was not enough.

I hunted around and came across a comment posted on the PEAR manual site. So courtesy of fredrik@krafftit.se I modded my code as follows and all worked well :)

$mimeParams = array(
 "text_encoding" => "8bit",
 "text_charset" => "UTF-8",
 "html_charset" => "UTF-8",
 "head_charset" => "UTF-8"
);

$body = $mime->get($mimeParams);

Thursday, 28 June 2012

How To Enable DB Mail in SQLEXPRESS 2008

By default SQL Server Express 2008 does not have DB mail enabled so you can't use the sp_send_dbmail stored procedure. You may have been getting the SQL Server blocked access to procedure 'dbo.sp_send_dbmail' error.

Quite a few articles I read, said that you can't use it - well - that's not strictly true! It's all there, it just has to be enabled :)

After I did this, SQLExpress was emailing just fine!

In Management Studio (SSMS), right click the server you want to enable DB mail on and choose Facets. In the View Facets pop-up choose the Surface Area Configuration option in the Facet dropdown. Then choose True for the DatabaseMailEnabled option.


Once you have clicked OK, you need to restart the SQL Express server (right click it and choose Restart).

The slightly more complicated part is that you now need to enter the data that other versions of SQL Server let you enter via the interface. So here goes:
  1. Expand the tables > system tables in the msdb database
  2. Create a mail account in sysmail_account
  3. Create a profile in sysmail_profile
  4. Match the new profile to the new account in sysmail_profileaccount (use the IDs from step 2 and 3)
  5. Create a mail server for the new account  in sysmail_server (the server type will probably be SMTP, but check in sysmail_servertype if you are unsure)
  6. Refresh the msdb DB, by right clicking the DB and choosing Refresh
Hey presto sp_send_dbmail now works :)

Thursday, 31 May 2012

Plesk - Checking the Mail Log

Do you need to check the mail logs on a Plesk server? Then here's an article on how to: http://www.hosting.com/support/plesk/check-the-mail-log-on-plesk-server

You can get access to it here:
/usr/local/psa/var/log/maillog

Tuesday, 15 May 2012

Test an IMAP Connection (Telnet)

Following on from post about how to test a POP3 connection using telnet, I thought I'd add a quick one about testing an IMAP connection. It's pretty much the same, but you use the 143 port number instead:

> telnet mail.mydomain.com 143
> login my_user_name my_password

Happy days :)


Update:
Recently I started getting an error when using the login command. Turns out I needed to do the following:


> 10 login my_user_name my_password


All subsequent commands needed to use 20, 30, etc. This is a good resource for more commands.

Tuesday, 18 October 2011

Unicode Characters in an Email Subject using PHP and PEAR

I've been working on a PHP site recently where I have had to cater for all languages and more importantly Unicode languages.

So after quite a lot of messing about and hunting around I found that I needed to do the following with the subject:

if (function_exists("mb_internal_encoding"))
 mb_internal_encoding("UTF-8");
if (function_exists("mb_encode_mimeheader"))
 $subject = mb_encode_mimeheader($subject, "UTF-8", "B", "\n");

Obviously if you know if the mb_* functions are available, then you can do away with the if statements.

This works using the PEAR Mail_Mime library. I haven't tested it with the built-in PHP mail function. I would assume it does not work.

Monday, 15 August 2011

The "SendUsing" Configuration Value is Invalid

I recently moved a VBScript script from one server to another. The new server did not have an SMTP server on it. When I ran the script (which emailed) I got a The "SendUsing" Configuration Value is Invalid error. Having already spent sometime recently using VBScript to email via Gmail, it was an easy fix for me. I specified the server and port and off it went!

Dim objMessage

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "MY_SUBJECT"
objMessage.From = "FROM_ADDRESS_SAME_AS_USER_NAME"
objMessage.To = "TO_ADDRESS"
objMessage.TextBody = "MY_MESSAGE"

objMessage.Configuration.Fields.Item( _
"http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item( _
"http://schemas.microsoft.com/cdo/configuration/smtpserver") = "IP_OR_NAME_OF_SERVER"
objMessage.Configuration.Fields.Item( _
"http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update

out = objMessage.Send
Set objMessage = Nothing

Friday, 15 July 2011

Sending Email using VBScript via Google Apps Mail / GMail

Following on from my previous post Sending Email using ASP.NET via Google Apps Mail / GMail, I have needed to send an email via GMail / Google Apps using VBScript. So here it is...

Dim objMessage

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "MY_SUBJECT"
objMessage.From = "FROM_ADDRESS_SAME_AS_USER_NAME"
objMessage.To = "TO_ADDRESS"
objMessage.TextBody = "MY_MESSAGE"

objMessage.Configuration.Fields.Item( _
"http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item( _
"http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
objMessage.Configuration.Fields.Item( _
"http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
objMessage.Configuration.Fields.Item( _
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objMessage.Configuration.Fields.Item( _
"http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
objMessage.Configuration.Fields.Item( _
"http://schemas.microsoft.com/cdo/configuration/sendusername") = "MY_USER_NAME"
objMessage.Configuration.Fields.Item( _
"http://schemas.microsoft.com/cdo/configuration/sendpassword") = "MY_PASSWORD"
objMessage.Configuration.Fields.Update

out = objMessage.Send
Set objMessage = Nothing

Tuesday, 19 April 2011

Test a POP3 Connection (Telnet)

I often find myself needing to be able to check a username and password combination for somebodies email connection (normally because they have forgotten their password - again!). A really quick and easy way to do this is using telnet. Here's the easiest way to do it, from the DOS/command prompt:

> telnet mail.mydomain.com
> user my_user_name
> pass my_password


At this point, if all is good, you will have made a successful connection. Show all messages as a list using:

> list

If you want to see the contents of a specific mail then use:

> retr mail_item_number

If you leave the connection with no activity then it close the connection itself, but preferably use:

> quit

There are some more telnet commands here. Also, if you using an IP address, you may well have to use a port number (usually 110). e.g. 123.123.123.123 110

Tuesday, 19 October 2010

Sending Email using ASP.NET via Google Apps Mail / GMail

I have recently moved all my hosting to go through Google Apps and it is sweet :)

This meant that I needed to modify my emailing routine in various .NET apps. A lot of this can be done via the Web.Config, but due to various reasons, I need to control it in code.

So configure your MailMessage object as per usual. I have added msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure; to mine, which could prove to be useful. Then configure your SmtpClient a follows:

SmtpClient smtp = new SmtpClient("smtp.gmail.com");
smtp.EnableSsl = true;
smtp.Timeout = 10000;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("email@mydomain.com", "my-password");
smtp.Send(msg);

Now a lot of articles I read suggested that you need to use port number 587 for the SmtpClient. When I did, I got the following error:

Request for the permission of type 'System.Net.Mail.SmtpPermission' failed

So I tried without declaring it and it worked just fine :)

A point worth noting: Make sure the account you are sending the email through is the same account that you are sending from.

Labels

.net (7) ajax (1) android (7) apache (1) asp.net (3) asus (2) blogger (2) blogspot (3) c# (16) compact framework (2) cron (1) css (1) data (1) data recovery (2) dns (1) eclipse (1) encryption (1) excel (1) font (1) ftp (1) gmail (5) google (4) gopro (1) html (1) iis (3) internet explorer IE (1) iphone (1) javascript (3) kinect (1) linux (1) macro (1) mail (9) mercurial (1) microsoft (3) microsoft office (3) monitoring (1) mootools (1) ms access (1) mssql (13) mysql (2) open source (1) openvpn (1) pear (2) permissions (1) php (12) plesk (4) proxy (1) qr codes (1) rant (4) reflection (3) regex (1) replication (1) reporting services (5) security (2) signalr (1) sql (11) sqlce (1) sqlexpress (1) ssis (1) ssl (1) stuff (1) svn (2) syntax (1) tablet (2) telnet (3) tools (1) twitter (1) unix (3) vb script (3) vb.net (9) vba (1) visual studio (2) vpc (2) vpn (1) windows (4) woff (1) xbox 360 (1)