使用system.web.mail.SMTPmail发送邮件,处理smtp验证问题

原创 2004年09月07日 12:57:00

无法对smtpserver进行设置,要对mailmessage进行设置。

http://systemwebmail.com/faq/3.8.aspx

Private Sub Page_Load(sender As Object, e As System.EventArgs)
   Dim mail As New MailMessage()
   mail.To = "me@mycompany.com"
   mail.From = "you@yourcompany.com"
   mail.Subject = "this is a test email."
   mail.Body = "Some text goes here"
   mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") 'basic authentication
   mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here") 'set your username here
   mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret") 'set your password here
   SmtpMail.SmtpServer = "mail.mycompany.com" 'your real server goes here
   SmtpMail.Send(mail)
End Sub 'Page_Load

我的代码:

Imports System
Imports System.Web.mail

Namespace SendMail

    Public Class usage
        Public Sub DisplayUsage()
            ' Display usage instructions in case of error.
            Console.WriteLine("Usage SendMail.exe <to> <from> <subject> <body>")
            Console.WriteLine("<to> the addresses of the email recipients")
            Console.WriteLine("<from> your email address")
            Console.WriteLine("<subject> subject of your email")
            Console.WriteLine("<body> the text of the email")
            Console.WriteLine("Example:")
            Console.WriteLine("SendMail.exe SomeOne@contoso.com;SomeOther@contoso.com Me@contoso.com Hi hello")
        End Sub
    End Class

    Public Class Start
        '  The main entry point for the application.
        Public Shared Sub Main(ByVal sTo As String, ByVal sFrom As String, ByVal sSub As String, ByVal sBody As String)
            Try
                Try
                    Dim Message As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
                    Message.To = sTo
                    Message.From = sFrom
                    Message.Subject = sSub
                    Message.Body = sBody

                    Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1")
                    Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "jetz")
                    Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "***")


                    Try
                        SmtpMail.SmtpServer = "smtp.263.net"
                        SmtpMail.Send(Message)
                    Catch ehttp As System.Web.HttpException
                        Console.WriteLine("0", ehttp.Message)
                        Console.WriteLine("Here is the full error message")
                        Console.Write("0", ehttp.ToString())
                    End Try
                Catch e As IndexOutOfRangeException
                    ' Display usage instructions if error in arguments.
                    Dim use As usage = New usage
                    use.DisplayUsage()
                End Try
            Catch e As System.Exception
                ' Display text of unknown error.
                Console.WriteLine("Unknown Exception occurred 0", e.Message)
                Console.WriteLine("Here is the Full Error Message")
                Console.WriteLine("0", e.ToString())
            End Try
        End Sub
    End Class

End Namespace
Module Module1
    Sub Main()
        'Dim k As New SendMail.usage
        'k.DisplayUsage()
        Dim m As New SendMail.Start
        m.Main("jetzwmx@126.com", "jetz@263.net", "hi", "hello")
        Console.ReadLine()
    End Sub
End Module

采用ASP.NET发送电子邮件(采用SMTP验证及SSL)

我们可以采用ASP.NET的System.Net.Mail来访问Smtp服务器发送邮件,代码如下:             MailAddress from = new MailAddress(@"h...
  • socrates
  • socrates
  • 2008-02-27 11:12:00
  • 2228

PHP用socket连接SMTP服务器发送邮件

PHP用socket连接SMTP服务器发送邮件 PHP用socket连接SMTP服务器发送邮件学习实验记录: 分析与SMTP会话的一般流程 1. HELO XXX \r\n //XX...
  • tty521
  • tty521
  • 2017-01-19 11:34:57
  • 1193

smtp 发送邮件 乱码解决

标题处理: $title="=?UTF-8?B?".base64_encode($title)."?="; 内容处理: $mail = new PHPMailer(); //建立邮件...
  • terry_water
  • terry_water
  • 2013-11-13 21:24:43
  • 1012

C++ SMTP协议发送邮件模块(支持身份验证)

  • 2010年09月17日 23:16
  • 16KB
  • 下载

perl利用SMTP发送邮件脚本(带认证)

#!/usr/bin/perl -wuse strict;use Net::SMTP;use Authen::SASL;(在SMTP服务器上要求用户认证,必须的模块)BEGIN {push (@INC...
  • zhangxinrun
  • zhangxinrun
  • 2010-07-09 14:39:00
  • 4255

通过SMTP SERVER 无需身份验证发送邮件

建立SMTP服务器发送匿名邮件   1.       系统:Windows XP/2000   2.       安装设置服务端     Windows XP和2000本身就拥有构件SMT...
  • wenlili
  • wenlili
  • 2012-02-18 09:30:21
  • 2959

一个通过smtp发送邮件的shell,带用户名密码

#!/bin/bashsmail(){ smtp="mail.mailadd.com 25" # 邮件服务器地址+25端口 smtp_domain="mailadd.c...
  • yiluoAK_47
  • yiluoAK_47
  • 2016-11-06 22:00:32
  • 1927

使用SMTP协议发送邮件

使用SMTP协议发送邮件,可以不通过SMTP服务器,直接将邮件发送到邮件服务器。很多服务器端程序可能需要向很多用户发送邮件,直接通过SMTP发送可能是最有效的。关于SMTP协议定义在RFC821,可以...
  • asklxf
  • asklxf
  • 2004-11-12 21:08:00
  • 8465

php使用smtp服务发送邮件 第一

define('SMTP_STATUS_NOT_CONNECTED', 1, true); define('SMTP_STATUS_CONNECTED', 2, true); class s...
  • zyu67
  • zyu67
  • 2014-12-20 10:58:32
  • 1278

PHPMailer通过Gmail和Office365的SMTP账号发送邮件设置

以下测试可用。 Gmail $mail = new PHPMailer();    $mail->IsSMTP(); $mail->SMTPAuth = true;  //主...
  • 0210
  • 0210
  • 2015-09-06 14:49:36
  • 3045
收藏助手
不良信息举报
您举报文章:使用system.web.mail.SMTPmail发送邮件,处理smtp验证问题
举报原因:
原因补充:

(最多只允许输入30个字)