Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
9 total  XML / RSS feed 

Authenticated SMTP in C#

// send smtp from from c#/.net

System.Web.Mail.MailMessage message=new System.Web.Mail.MailMessage();

message.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",1 );
message.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendusername","SmtpHostUserName" );
message.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword","SmtpHostPassword" );

message.From="from e-mail";
message.To="to e-mail";
message.Subject="Message Subject";
message.Body="Message Body";

System.Web.Mail.SmtpMail.SmtpServer="SMTP Server Address";
System.Web.Mail.SmtpMail.Send(message);

MailMan listserve signup template

Simple template for adding a MailMan mailing list subscribe form to a page. Found on a mailing list somewhere a long time ago and cleaned up dramatically.

Note: I almost always just include the email and digest options, but I've included the whole spiel for completeness.


<h2>Join the XYZ listh2>

/mailman/subscribe/LISTNAME">

Your E-mail address: "text" name="email" size="30" value="">
Your Name (optional): "text" name="fullname" size="30" value="">

You may enter a privacy password below. This provides only mild security, but should
prevent others from messing with your subscription. Do not use a valuable password as it
will occasionally be emailed back to you in cleartext.

If you choose not to enter a password, one will be automatically generated for you, and it will
be sent to you once you've confirmed your subscription. You can always request a mail-back
of your password when you edit your personal options.

Password choice: "password" name="pw" size="15">
Confirm Password: "password" name="pw-conf" size="15">

Would you like to receive list mail batched in a daily digest? (You may choose NoMail after you join.)
"radio" name="digest" value="0" checked> No "radio" name="digest" value="1"> Yes

"submit" name="email-button" value="Subscribe">


Speed up Mail.app

// Speed up Mail.app with this shell command (backup the file first)

sqlite3 "~/Library/Mail/Envelope Index" vacuum;

mail - check on terminal

mail.wahu.de 110
user xxx
pass xxx

send mail with :login

// with ":login" you authenticate with user and password
// more info: Library Net:SMTP [Dave Thomas, The Pragmatc Programmer]
  # send email with :login
  def send_email(subject, message)
   
    from='sender@sender_address.de'
    from_alias='the sender'
    to='recipient@recip_address.de'
    to_alias='the recipient'
    smtp_host='smtp.1und1.com'
    port=25   # default port is 25
    user='username'
    password='its_a_secret'

    myMessage = <<END_OF_MESSAGE
From: #{from_alias} <#{from}>
To: #{to_alias} <#{to}>
Subject: #{subject}

#{message}
END_OF_MESSAGE

    Net::SMTP.start(smtphost, port, from, user, password, :login) do |smtp|
      smtp.send_message myMessage, from, to
    end
  end

Find flagged message subjects in maildir

Simple, perhaps slightly cryptic oneliner to get the subjects of all flagged messages in a Maildir. It assumes that 'F' is the flag for flagged messages (as it almost always is) and that your message files end with ":2,".

find ~/Maildir -type f -name "*:2,*F*" -exec egrep -h "^Subject:" "{}" ";" | cut -c 10-

Quick Mail class

// Quick Mail class

    static class QuickMail
    {
        public static void SendMail(string from, string to, string subject, string messageText, bool isHtml)
        {
                        SmtpClient mymail = new SmtpClient(ConfigurationManager.AppSettings["localsmtp"]);
                        MailMessage message = new MailMessage(from, to, subject, messageText);
                        message.IsBodyHtml = isHtml;
                        mymail.Send(message);
        }
    }

Changing your hostname which your mail server sends out

Occassionaly you have a internal mailserver on a machine which has a hostname like machine.example but for mail purposes your machine is known to the outside world as mail.example.com one can use the following helo_data on in your transports for exim to announce yourself as mail.example.com:

remote_smtp:
  driver = smtp
  helo_data = mail.example.com

exim router for relaying via a smarthost

User the "begin routers" section add:

route_append:
    driver = manualroute
    domains = *
    transport = remote_smtp
    route_data = "smarthost.host.name byname"
« Newer Snippets
Older Snippets »
9 total  XML / RSS feed