2016-09-21 2 views
0

주소가 Web.config 인 SMTP를 가져오고 싶습니다. 아래 코드는 Web.config 파일의 코드입니다. 내 컨트롤러에서FromEmail 주소의 Web.config 파일에서 읽음

system.net> 
    <mailSettings> 
     <smtp from="[email protected]"> 

, 나는이 어떻게해야 마십시오 Web.config 데이터를 읽고 싶어?

아래 코드를 사용했지만 작동하지 않았습니다. 당신의 Web.config에

var fromAddress = new MailAddress("[email protected]", "From Name"); //Add from email from web config file 
+0

가능한 중복 질문 http://stackoverflow.com/a ! MAYANK의 이메일 - -> /11945231) –

답변

1

추가 이메일 주소

<appSettings> 
    <add key="FromEmail" value="[email protected]" /> 
    </appSettings> 

그리고 컨트롤러에 그것을 얻을 :

string Email = ConfigurationManager.AppSettings["FromEmail"]; 

편집 : 영업 이익은 config 파일에서 mailSettings 있습니다

<system.net> 
     <mailSettings> 
     <smtp from="[email protected]"> <!--EMAIL FROM MAYANK--> 
      <network host="smtp.gmail.com" port="587" userName="[email protected]" password="yourpassword" enableSsl="true"/> </smtp> 
    </mailSettings> 
</system.net> 
이처럼 사용할 수있는 경우

:

var msgSettings = new MailMessage(); 

var Email = msgSettings.From.Address; 
+0

나는 = "[email protected]"이미 @Div –

+0

<에서

0

구성 코드에 SMTP 당신은 대답 [여기]를 (볼 수 있습니다

SmtpClient smtp = new SmtpClient("smtp.gmail.com", 465); 
smtp.Credentials = new NetworkCredential("[email protected]", "***"); 
smtp.EnableSsl = true; 
smtp.Send(mail); 
관련 문제