Пример за изпращане на e-mail чрез автентификация ( Намерих примера в Internet):
If you don't need to authenticate, leave the last 3 parameters blank (just send empty strings), else fill in w/ your smtp server and login info.
[WebMethod (Description="Simple mailer w/ authentication")]
public string SimpleMail(string mailto, string mailfrom, string mailsubject, string mailbody, string mailcc, string mailbcc, string smtpserver, string username, string password)
{
string _results = "success!";
MailMessage mm = new System.Web.Mail.MailMessage();
mm.From = mailfrom;
mm.To = mailto;
mm.Subject = mailsubject;
mm.Body = mailbody;
mm.Cc = mailcc;
mm.Bcc = mailbcc;
mm.BodyFormat = MailFormat.Text;
int cdoBasic = 1;
int cdoSendUsingPort = 2;
mm.Fields.Add("http://www.blogger.com/'http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", cdoBasic);
mm.Fields.Add("http://www.blogger.com/'http://schemas.microsoft.com/cdo/configuration/sendusername", username);
mm.Fields.Add("http://www.blogger.com/'http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
mm.Fields.Add("http://www.blogger.com/'http://schemas.microsoft.com/cdo/configuration/sendusing", cdoSendUsingPort);
mm.Fields.Add("http://www.blogger.com/'http://schemas.microsoft.com/cdo/configuration/smtpserver", smtpserver);
mm.Fields.Add("http://www.blogger.com/'http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 10);
mm.Fields.Add("http://www.blogger.com/'http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);
mm.Fields.Add("http://www.blogger.com/'http://schemas.microsoft.com/cdo/configuration/smtpusessl", false);
try
{
System.Web.Mail.SmtpMail.Send(mm);
}
catch (Exception e)
{
_results = e.ToString();
}
return _results;
}
Няма коментари:
Публикуване на коментар