2012-07-11 1 views
0

그래서 백엔드를 정리하고 이메일을 정리하려고합니다. html 파일을 여기에 직접 넣는 대신에 html 파일에 include하는 방법이 있습니까? 아니면 더 좋은 방법일까요? 당신이 ASP.Net MVC를 사용하는 경우.cs C# .net에 HTML 페이지를 포함하십시오.

public void SendWelcomeEmail(int uid) 
{ 
SqlCommand command = EmailCommandList.GetRegisteredEmail; 
BciDatabase db = new BciDatabase("db"); 
command.Parameters["@User_Id"].Value = uid; 
using (SqlDataReader dr = db.ExecuteReader(command)) 
{ 
Member member = new Member(); 
if (dr != null && !dr.IsClosed && dr.Read()) 
{ 
while (dr.Read()) 
{ 
string emailAddress = (string)dr["Email"]; 
MailMessage mail = new MailMessage(); 
mail.Subject = "Welcome to the site"; 
mail.Body = "<html><head></head><body><p>Hello, welcome to the site!</body></html>"; 
mail.IsBodyHtml = true; 
mail.From = new MailAddress("[email protected]"); 
mail.To.Add(new MailAddress(emailAddress)); 
var client = new SmtpClient("smtp.gmail.com", 587) 
{ 
Credentials = new NetworkCredential("myemail", "mypass"), 
EnableSsl = true 
}; 
client.Send(mail); 
} 
} 
} 
} 
+0

외부 파일의 내용을 문자열 변수로 읽고 'mail.Body = fileContents;'를 설정할 수 있습니다. –

+0

어떻게해야합니까? Im new – tytyguy

답변

2

(예 : 사람의 이름) 모델의 요소를 쉽게 주입 할 수있는보기로 이메일을 쓸 수있는 몇 가지 정말 좋은 솔루션이 있습니다

당신이 MVC를 사용하지 않는 경우

, 당신은 확실히 파일 시스템에서 HTML 파일을 읽거나, HTML의 F를 읽을 수 있습니다 ROM에 데이터베이스 (당신은 몇 가지 이메일 이상을 가지고 있다면 유지 보수가 훨씬 쉽다).

+0

ASP.Net Webforms (yuck!)를 사용하는 경우에도 우편은 여전히 ​​유용합니다. 추천. 참조 : http://stackoverflow.com/questions/11368677/how-to-build-html-messages-in-an-mvc3-application-for-sending –

+0

그럴 수도 있다고 생각했지만 올해는 Webforms를 완료하지 않았습니다. 그리고 년 :-) 그것을 공유해 주셔서 감사합니다. –

관련 문제