• Авторизация


SendMail ASP.NET 29-02-2012 18:29 к комментариям - к полной версии - понравилось!


PHP:

public static bool SendEmail(
        
string pGmailEmail
        
string pGmailPassword
        
string pTo
        
string pSubject,
        
string pBody
        
System.Web.Mail.MailFormat pFormat,
        
string pAttachmentPath)
    {
        try
        {
            
System.Web.Mail.MailMessage myMail = new System.Web.Mail.MailMessage();
            
myMail.Fields.Add
                
("http://schemas.microsoft.com/cdo/configuration/smtpserver",
                              
"smtp.gmail.com");
            
myMail.Fields.Add
                
("http://schemas.microsoft.com/cdo/configuration/smtpserverport",
                              
"465");
            
myMail.Fields.Add
                
("http://schemas.microsoft.com/cdo/configuration/sendusing",
                              
"2");
            
//sendusing: cdoSendUsingPort, value 2, for sending the message using 
            //the network.
 
            //smtpauthenticate: Specifies the mechanism used when authenticating 
            //to an SMTP 
            //service over the network. Possible values are:
            //- cdoAnonymous, value 0. Do not authenticate.
            //- cdoBasic, value 1. Use basic clear-text authentication. 
            //When using this option you have to provide the user name and password 
            //through the sendusername and sendpassword fields.
            //- cdoNTLM, value 2. The current process security context is used to 
            // authenticate with the service.
            
myMail.Fields.Add
            
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate","1");
            
//Use 0 for anonymous
            
myMail.Fields.Add
            
("http://schemas.microsoft.com/cdo/configuration/sendusername",
                
pGmailEmail);
            
myMail.Fields.Add
            
("http://schemas.microsoft.com/cdo/configuration/sendpassword",
                 
pGmailPassword);
            
myMail.Fields.Add
            
("http://schemas.microsoft.com/cdo/configuration/smtpusessl",
                 
"true");
            
myMail.From pGmailEmail;
            
myMail.To pTo;
            
myMail.Subject pSubject;
            
myMail.BodyFormat pFormat;
            
myMail.Body pBody;
            if (
pAttachmentPath.Trim() != "")
            {
                
MailAttachment MyAttachment 
                        new 
MailAttachment(pAttachmentPath);
                
myMail.Attachments.Add(MyAttachment);
                
myMail.Priority System.Web.Mail.MailPriority.High;
            }
 
            
System.Web.Mail.SmtpMail.SmtpServer "smtp.gmail.com:465";
            
System.Web.Mail.SmtpMail.Send(myMail);
            return 
true;
        }
        catch (
Exception ex)
        {
            throw;
        }
    }
font>



PHP:

//E-mail using
using System.Web;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
А вот уже и сама отправкапривёл примердля отправки письма с вложением.
//Авторизация на SMTP сервере
SmtpClient Smtp = new SmtpClient("smtp.mail.ru"25);
Smtp.Credentials = new NetworkCredential("login""pass");
//Smtp.EnableSsl = false;
 
//Формирование письма
MailMessage Message = new MailMessage();
Message.From = new MailAddress("from@mail.ru");
Message.To.Add(new MailAddress("to@mail.ru"));
Message.Subject "Заголовок";
Message.Body "Сообщение";
 
         
//Прикрепляем файл
         
string file "C:\file.zip";
         
Attachment attach = new Attachment(fileMediaTypeNames.Application.Octet);
 
         
// Добавляем информацию для файла
         
ContentDisposition disposition attach.ContentDisposition;
         
disposition.CreationDate System.IO.File.GetCreationTime(file);
         
disposition.ModificationDate System.IO.File.GetLastWriteTime(file);
         
disposition.ReadDate System.IO.File.GetLastAccessTime(file);
 
         
Message.Attachments.Add(attach);
 
Smtp.Send(Message);//отправка
font>

вверх^ к полной версии понравилось! в evernote


Вы сейчас не можете прокомментировать это сообщение.

Дневник SendMail ASP.NET | vlad275 - Дневник vlad275 | Лента друзей vlad275 / Полная версия Добавить в друзья Страницы: раньше»