C# SMTP Mail Console
Send Mail by C# in console. Simple view use of a class , properties (get/set) you can test it by using .NET SDK framework compile it with the csc command in console c:> csc ClsMail.cs after compiling it will give you the exe file
AI
KI-Zusammenfassung: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Quellcode
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2 BGCOLOR=#1FC0D0>
<TR><TD>
<TT><PRE>using System;
using System.Web.Mail;
namespace myMail
{
/// <summary>
/// Summary description for ClsStartup.
/// </summary>
public class ClsMail
{
private string mTxtEmailTo; // Emailaddres for user to send
private string mTxtEmailFrom; // Emailaddres for user from
private string mTxtMailSubj;
private string mTxtMailBody;
private string mTxtServerName;
public ClsMail()
{
Console.WriteLine ("Console SMTP Mail V0.1");
Console.WriteLine ("----------------------");
mTxtEmailFrom = "";
mTxtEmailTo = "";
}
public string SmtpServer
{
set
{
mTxtServerName = value;
SmtpMail.SmtpServer = value;
}
get
{
return mTxtServerName;
}
}
public string EmailFrom
{
set
{
mTxtEmailFrom = value;
}
get
{
return mTxtEmailFrom;
}
}
public string EmailTo
{
set
{
mTxtEmailTo = value;
}
get
{
return mTxtEmailTo;
}
}
public string MailBody
{
set
{
mTxtMailBody = value;
}
get
{
return mTxtMailBody;
}
}
public string MailSubject
{
set
{
mTxtMailSubj = value;
}
get
{
return mTxtMailSubj;
}
}
public bool SendNow()
{
try
{
Console.WriteLine();
Console.WriteLine("Connecting to : {0}" , mTxtServerName);
SmtpMail.Send (mTxtEmailFrom,mTxtEmailTo,mTxtMailSubj,
mTxtMailBody);
return true;
}
catch (Exception e)
{
Console.WriteLine("Error Mail Sending : {0}" , e.Message );
return false;
}
}
/// <summary>
/// Startup Method
/// </summary>
[STAThread]
static void Main(string[] args)
{
/// Header MainApplication
ClsMail Smtp = new ClsMail();
Console.Write("Smtp server : ");
Smtp.SmtpServer = Console.ReadLine();
Console.Write("Your Emailaddr : ");
Smtp.EmailFrom = Console.ReadLine();
Console.Write("Email To Send : ");
Smtp.EmailTo = Console.ReadLine();
Console.Write("Subject Mail : ");
Smtp.MailSubject = Console.ReadLine();
Console.Write("Body : ");
Smtp.MailBody = Console.ReadLine();
if (Smtp.SendNow())
{
Console.WriteLine("End Session : Succesfully");
}
else
{
Console.WriteLine("End Session : Failed");
}
Console.WriteLine("Press any Key");
Console.Read();
}
}
}</PRE></TT>
</TD></TR>
</TABLE>
Originalkommentare (3)
Wiederhergestellt von der Wayback Machine