Use. Net to send Hotmail (XMLHTTP, but the test fails)

Source: Internet
Author: User
Tags rfc mail time
I found that Hotmail is not supported now (I hope I understand it wrong ?) Outlook, outlookexpress and other clients have sent and received emails.
However, I still want to stick to my attitude towards technological learning.

CoreCodeAs follows:

Public   Void Sendmail ( String From, String Fromname, String To, String Subject, String Body, String Username, String Password)
{
// We begin by setting up a quote string (used later) as well generating a mail time stamp:

// Quote character.
String Quote =   " \ U0022 " ;
// Generate the time stamp.
Datetime now = Datetime. now;
String Timestamp = Now. tostring ( " DDD, DD Mmm yyyy hh: mm: SS " );

// The httpmail Protocol follows an SMTP-like communication scheme (see RFC 821). Outlook Express sends out mail in MIME format, but for demonstrations purposes we simply send a plain text E-mail:

// Build the post body.
String Postbody =   Null ;
// Dump mail headers.
Postbody + =   " Mail from: < "   + From +   " > \ R \ n " ;
Postbody + =   " Rcpt to: < "   + To +   " > \ R \ n " ;
Postbody + =   " \ R \ n " ;
Postbody + =   " From: "   + Quote + Fromname + Quote +   " < "   + From +   " > \ R \ n " ;
Postbody + =   " To: < "   + To +   " > \ R \ n " ;
Postbody + =   " Subject: "   + Subject + " \ R \ n " ;
Postbody + =   " Date: "   + Timestamp +   " -0000 \ n " ;
Postbody + =   " \ R \ n " ;
// Dump mail body.
Postbody + = Body;

// To send the mail, we need to set the Content-Type request header to message/rfc821, indicating that this request contains a body which follows RFC 821. we post the Request body generated abve to the sendmsg URL obtained during connection time:

XMLHTTP _ =   New XMLHTTP ();

// Open the connection.
XMLHTTP _. Open ( " Post " , Serverurl, False , Username, password );
// Send the request.
XMLHTTP _. setRequestHeader ( " Content-Type " , " Message/rfc821 " );
XMLHTTP _. Send (postbody );

MessageBox. Show (XMLHTTP _. statustext ); // XMLHTTP _. responsetext;
}

In the last line, the original code uses XMLHTTP _. responsetext to read no data, but uses statustext to receive the Hotmail response:---------------------------
Access to Hotmail via Outlook and Outlook Express now requires a submodules. Please sign up at http://upgrade.msn.com
---------------------------

Of course, there are other alternatives for you to use hotmail to send emails ....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.