閣下現正於: 客戶服務中心之主頁 > 知識庫 / 常問問題 > 02) 伺服器使用問題 (Window) > 使用(ASP/C# 1.1, 2.0/VB.net 1.1, 2.0 ) 程式語言,發送電郵 SMTP Authentication (Code Sample). 登入 or 賬戶登記

  Linux 網站及電郵寄存服務
    企業 
    個人 / 學生 / 論壇  
  Windows 網站及電郵寄存服務
  Email 電郵寄存服務
  域名 登記服務
  SSL 數碼證書
  網上商店
  Linux 網頁寄存代理商

Rank: 1

使用(ASP/C# 1.1, 2.0/VB.net 1.1, 2.0 ) 程式語言,發送電郵 SMTP Authentication (Code Sample).

ASP

 <%
 Dim ObjSendMail
 Set ObjSendMail = Server.CreateObject("Persits.MailSender")
 
 ObjSendMail.Host = "mail.somesite.com"
 ObjSendMail.From = "someone@somesite.com"
 ObjSendMail.FromName = "someone"
 ObjSendMail.AddAddress "somebodyelse@somesite.com"
 ObjSendMail.Subject = "your subject"
 ObjSendMail.Body = "your email body"
  
 'If Your email server requires SMTP Authentication uncomment and use the values below  
  'ObjSendMail.Username = "SMTPUsername"
  'ObjSendMail.Password = "SMTPPassword"
 
 On Error Resume Next
 
 ObjSendMail.Send
 If Err <> 0 Then
    Response.Write "Error encountered: " & Err.Description
 End
If
 
 Set ObjSendMail = nothing
%>

 

C# 1.1

private void Page_Load(object sender, System.EventArgs e)
{
 MailMessage mail = 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 );
}


C# 2.0

static void Authenticate()
{
//create the mail message
MailMessage mail = new MailMessage();

//set the addresses
mail.From = new MailAddress("me@mycompany.com");
mail.To.Add("you@yourcompany.com");

//set the content
mail.Subject = "This is an email";
mail.Body = "this is the body content of the email.";

//send the message
SmtpClient smtp = new SmtpClient("mail.yourdomain.com");

//to authenticate we set the username and password properites on the SmtpClient
smtp.Credentials = new NetworkCredential("username@yourdomain.com", "secret");
smtp.Send(mail);

}


VB.net 1.1

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


VB.net 2.0

<%@ Import Namespace="System.Net.Mail" %>

Sub Authenticate()
'create the mail message
Dim mail As New MailMessage()

'set the addresses
mail.From = New MailAddress("me@mycompany.com")
mail.To.Add("you@yourcompany.com")

'set the content
mail.Subject = "This is an email"
mail.Body = "this is the body content of the email."

'send the message
Dim smtp As New SmtpClient("mail.yourdomain.com")

'to authenticate we set the username and password properites on the SmtpClient
smtp.Credentials = New NetworkCredential("username@yourdomain.com", "secret")
smtp.Send(mail)
End Sub 'Authenticate

 



此答案有用嗎?

加入到最愛 加入到最愛

列印此文章 列印此文章


選擇語言: