IRCForumları - IRC ve mIRC Kullanıcılarının Buluşma Noktası

IRCForumları - IRC ve mIRC Kullanıcılarının Buluşma Noktası (https://www.ircforumlari.net/)
-   C# (https://www.ircforumlari.net/c/)
-   -   C# projeleriniz için e-posta yollama sınıfı (https://www.ircforumlari.net/c/124395-c-projeleriniz-icin-e-posta-yollama-sinifi.html)

Cemalizim 19 Temmuz 2008 15:52

C# projeleriniz için e-posta yollama sınıfı
 
C# uygulamalarınızda kullanabileceğiniz, SMTP bilgilerini girerek uygulama içinden e-posta yollamanızı sağlayan sınıf ve örnek kullanım kodları

PHP- Kodu:

/// Örnek kullanım:
EnhancedMailMessage msg = new EnhancedMailMessage();

msg.From "
Bu forumdaki linkleri ve resimleri görebilmek için en az 25 mesajınız olması gerekir.
"
;
msg.FromName "Gönderen Adı";
msg.To "
Bu forumdaki linkleri ve resimleri görebilmek için en az 25 mesajınız olması gerekir.
"
;
msg.Subject "Konu";
msg.Body "Mesaj";

msg.SMTPServerName "smtp.sunucu.com";
msg.SMTPUserName "kullanici";
msg.SMTPUserPassword "parola";

msg.Send();




/// Sınıf kodları:
public class EnhancedMailMessage MailMessage
{
    private 
string fromName;
    private 
string smtpServerName;
    private 
string smtpUserName;
    private 
string smtpUserPassword;
    private 
int smtpServerPort;
    private 
bool smtpSSL;

    public 
EnhancedMailMessage()
    {
        
fromName string.Empty;
        
smtpServerName string.Empty;
        
smtpUserName string.Empty;
        
smtpUserPassword string.Empty;
        
smtpServerPort 25;
        
smtpSSL false;
    }

    
/// <summary>
    /// The display name that will appear
    /// in the recipient mail client
    /// </summary>
    
public string FromName 
    
{
        
set 
        
{
            
fromName value;
        }
        
get 
        
{
            return 
fromName;
        }
    }

    
/// <summary>
    /// SMTP server (name or IP address)
    /// </summary>
    
public string SMTPServerName 
    
{
        
set 
        
{
            
smtpServerName value;
        }
        
get 
        
{
            return 
smtpServerName;
        }
    }

    
/// <summary>
    /// Username needed for a SMTP server
    /// that requires authentication
    /// </summary>
    
public string SMTPUserName 
    
{
        
set 
        
{
            
smtpUserName value;
        }
        
get 
        
{
            return 
smtpUserName;
        }
    }
    
    
/// <summary>
    /// Password needed for a SMTP server
    /// that requires authentication
    /// </summary>
    
public string SMTPUserPassword 
    
{
        
set 
        
{
            
smtpUserPassword value;
        }
        
get 
        
{
            return 
smtpUserPassword;
        }
    }
    
    
/// <summary>
    /// SMTP server port (default 25)
    /// </summary>
    
public int SMTPServerPort 
    
{
        
set 
        
{
            
smtpServerPort value;
        }
        
get 
        
{
            return 
smtpServerPort;
        }
    }
    
    
/// <summary>
    /// If SMTP server requires SSL
    /// </summary>
    
public bool SMTPSSL
    
{
        
set 
        
{
            
smtpSSL value;
        }
        
get 
        
{
            return 
smtpSSL;
        }
    }

    public 
void Send() 
    {
        if (
smtpServerName.Length == 0
        {
            throw new 
Exception("SMTP Server not specified");
        }

        if (
fromName.Length 0
        {
            
this.Headers.Add("From"
                 
string.Format("{0} <{1}>"
                 
FromNameFrom));            
        }

        
// set SMTP server name
        
this.Fields["http://schemas.microsoft.com/" 
                    
"cdo/configuration/smtpserver"] = smtpServerName;
        
// set SMTP server port
        
this.Fields["http://schemas.microsoft.com/cdo" 
                    
"/configuration/smtpserverport"] = smtpServerPort;
        
this.Fields["http://schemas.microsoft.com/" 
                    
"cdo/configuration/sendusing"] = 2;

        if (
smtpUserName.Length >&& smtpUserPassword.Length 0
        {
            
this.Fields["http://schemas.microsoft.com/" 
                        
"cdo/configuration/smtpauthenticate"] = 1;
            
            
// set SMTP username
            
this.Fields["http://schemas.microsoft.com" 
                 
"/cdo/configuration/sendusername"] = smtpUserName;
            
// set SMTP user password
            
this.Fields["http://schemas.microsoft.com/" 
                 
"cdo/configuration/sendpassword"] = smtpUserPassword;
        }

        
// ssl if needed
        
if (smtpSSL
        {
            
this.Fields.Add("http://schemas.microsoft" 
                 
".com/cdo/configuration/smtpusessl""true");
        }

        
SmtpMail.SmtpServer smtpServerName;
        
SmtpMail.Send(this);
    }

    public static 
void QuickSend(
        
string SMTPServerName
        
string ToEmail
        
string FromEmail
        
string Subject
        
string Body
        
MailFormat BodyFormat
    {
        
EnhancedMailMessage msg = new EnhancedMailMessage();

        
msg.From FromEmail;
        
msg.To ToEmail;
        
msg.Subject Subject;
        
msg.Body Body;
        
msg.BodyFormat BodyFormat;

        
msg.SMTPServerName SMTPServerName;
        
msg.Send();
    }


Alıntı


Tüm Zamanlar GMT +3 Olarak Ayarlanmış. Şuanki Zaman: 22:43.

Powered by vBulletin® Version 3.8.8 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO
Copyright ©2004 - 2024 IRCForumlari.Net