コード例 #1
0
 private void SetSessionProperties(GXSMTPSession session)
 {
     host             = session.Host;
     port             = session.Port;
     authentication   = (session.Authentication == 1);
     secureConnection = (session.Secure == 1);
     userName         = session.UserName;
     password         = session.Password;
     timeout          = session.Timeout;
 }
コード例 #2
0
 public void Logout(GXSMTPSession session)
 {
     try
     {
         Logout();
     }
     catch (GXMailException exc)
     {
         session.HandleMailException(exc);
     }
 }
コード例 #3
0
        public void Send(GXSMTPSession session, GXMailMessage msg)
        {
            try
            {
                if ((msg.To.Count == 0) && (msg.CC.Count == 0) && (msg.BCC.Count == 0))
                {
                    throw new GXMailException("No main recipient specified", MAIL_NoRecipient);
                }

                try
                {
                    SendAndWaitResponse("MAIL FROM: <" + session.Sender.Address + ">", "2", MAIL_MessageNotSent);

                    SendRecipientList(msg.To);
                    SendRecipientList(msg.CC);
                    SendRecipientList(msg.BCC);

                    SendAndWaitResponse("DATA", "354", MAIL_MessageNotSent);

                    SendNL("FROM: \"" + ToEncodedString(session.Sender.Name) + "\" <" + session.Sender.Address + ">");
                    SendAllRecipients(msg.To, GXInternetConstants.TO);
                    SendAllRecipients(msg.CC, GXInternetConstants.CC);
                    SendAllRecipients(msg.ReplyTo, GXInternetConstants.REPLY_TO);

                    SendNL("MIME-Version: 1.0");
                    SendNL("SUBJECT: " + ToEncodedString(msg.Subject));
                    SendNL("DATE: " + GetNowAsString());

                    foreach (string key in msg.Headers.Keys)
                    {
                        SendNL(String.Format("{0}: {1}", key, msg.Headers[key]));
                    }

                    string sTime       = DateTime.Now.Ticks.ToString();
                    bool   isMultipart = ((msg.HTMLText.Length > 0) || (msg.Attachments.Count > 0));

                    if (msg.Attachments.Count > 0)
                    {
                        SendNL("Content-Type: multipart/mixed;boundary=\"" +
                               getStartMessageIdMixed(sTime) +
                               "\"\r\n\r\nThis message is in MIME format. Since your mail reader does not understand\r\nthis format, some or all of this message may not be legible.\r\n\r\n" +
                               getNextMessageIdMixed(sTime, false));
                    }

                    if ((msg.HTMLText.Length > 0) && (msg.Text.Length > 0))
                    {
                        SendNL("Content-Type: multipart/alternative;boundary=\"" +
                               getStartMessageIdAlternative(sTime) +
                               "\"\r\n\r\nThis message is in MIME format. Since your mail reader does not understand\r\nthis format, some or all of this message may not be legible.\r\n\r\n");
                    }

                    if (msg.Text.Length > 0)
                    {
                        SendNL("Content-Type:text/plain; charset=\"UTF-8\"\r\n");
                        SendTextUTF8(msg.Text);

                        if (msg.HTMLText.Length > 0)
                        {
                            SendNL("\r\n\r\n" + getNextMessageIdAlternative(sTime, false));
                        }
                    }

                    if (msg.HTMLText.Length > 0)
                    {
                        SendNL("Content-Type: text/html; charset=\"UTF-8\"\r\n");

                        SendTextUTF8(msg.HTMLText);
                        SendNL("");

                        if (msg.Text.Length > 0)
                        {
                            SendNL(getNextMessageIdAlternative(sTime, true));
                        }
                    }
                    SendAttachments(sTime, msg.Attachments, session.AttachDir);
                }
                catch (Exception exc)
                {
                    throw new GXMailException(exc.Message, MAIL_ConnectionLost);
                }

                SendAndWaitResponse(CRLF + ".", "2", MAIL_MessageNotSent);
            }
            catch (GXMailException exc)
            {
                session.HandleMailException(exc);
            }
        }
コード例 #4
0
 public void Login(GXSMTPSession session)
 {
     SetSessionProperties(session);
     ConnectAndLogin();
 }