Gmail을 통해 .NET으로 이메일 보내기

호스트에게 이메일을 보내는 대신 제 Gmail 계정을 사용하여 이메일 메시지를 보내려고 생각했습니다. 이메일은 제 쇼에서 연주하는 밴드에게 개인화된 이메일입니다. 가능한가요?

질문에 대한 의견 (11)
해결책

더 이상 사용되지 않는 System.Web.Mail이 아닌 System.Net.Mail을 사용해야 합니다. System.Web.Mail`로 SSL을 사용하면 해킹 확장 프로그램이 엉망이 됩니다.

using System.Net;
using System.Net.Mail;

var fromAddress = new MailAddress("from@gmail.com", "From Name");
var toAddress = new MailAddress("to@example.com", "To Name");
const string fromPassword = "fromPassword";
const string subject = "Subject";
const string body = "Body";

var smtp = new SmtpClient
{
    Host = "smtp.gmail.com",
    Port = 587,
    EnableSsl = true,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    UseDefaultCredentials = false,
    Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
    Subject = subject,
    Body = body
})
{
    smtp.Send(message);
}
해설 (29)

위의 답변은 작동하지 않습니다. '배달 방법 = SmtpDeliveryMethod.Network'를 설정해야 하며, 그렇지 않으면 '** 클라이언트가 인증되지 않았습니다'라는 오류와 함께 다시 돌아옵니다. 또한 항상 타임아웃을 설정하는 것이 좋습니다.

코드를 수정했습니다:

using System.Net.Mail;
using System.Net;

var fromAddress = new MailAddress("from@gmail.com", "From Name");
var toAddress = new MailAddress("to@yahoo.com", "To Name");
const string fromPassword = "password";
const string subject = "test";
const string body = "Hey now!!";

var smtp = new SmtpClient
{
    Host = "smtp.gmail.com",
    Port = 587,
    EnableSsl = true,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    Credentials = new NetworkCredential(fromAddress.Address, fromPassword),
    Timeout = 20000
};
using (var message = new MailMessage(fromAddress, toAddress)
{
    Subject = subject,
    Body = body
})
{
    smtp.Send(message);
}
해설 (5)

다른 답변을 통해 &quot 작동합니까 server"; 먼저 서비스하고 있는 보다 안전한 어플리케이션 선반가공 gmail 계정.

최근 구글 변경일 it& # 39, 안보의 총결산을 하는 것처럼 보인다. 더 이상 작동하지 않는 이 최고 오토메이티드 변경할 때까지 입금합니다 설정으로 설명됨 있습니다. https://support.google.com/accounts/answer/6010255? hl = en - gb ! [입력하십시오. 이미지 여기에 설명을] [1]

! [입력하십시오. 이미지 여기에 설명을] [2]

3월 2016년, 구글은 위치 설정! 으로 다시 바꿨다.

해설 (4)

이를 통해 이메일 첨부 파일. 단순하고 파선-짧은.

출처: http://coding-issues.blogspot.in/2012/11/sending-email-with-attachments-from-c.html

using System.Net;
using System.Net.Mail;

public void email_send()
{
    MailMessage mail = new MailMessage();
    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
    mail.From = new MailAddress("your mail@gmail.com");
    mail.To.Add("to_mail@gmail.com");
    mail.Subject = "Test Mail - 1";
    mail.Body = "mail with attachment";

    System.Net.Mail.Attachment attachment;
    attachment = new System.Net.Mail.Attachment("c:/textfile.txt");
    mail.Attachments.Add(attachment);

    SmtpServer.Port = 587;
    SmtpServer.Credentials = new System.Net.NetworkCredential("your mail@gmail.com", "your password");
    SmtpServer.EnableSsl = true;

    SmtpServer.Send(mail);

}
해설 (0)

구글 apps 에서 사용하지 않는 일부 시도_횟수 로그인하십시오 차단할 수 또는 디바이스입니다 현대의 보안 표준이다. 이 장치는 진입을 막고, 그 이후 앱과 입금합니다 보다 쉽게 할 수 있습니다.

앱 최신 보안 표준을 지원하지 않는 몇 가지 예는 다음과 같다.

  • 아이폰 아이패드 iOS 6 또는, 또는 메일 app 에 있는 below&lt br /&gt.
  • 윈도우 폰 8.1 release&lt 메일 app 에 이전, br /&gt.
  • 일부 데스크탑입니다 마이크로소프트 아웃룩 같은 메일 클라이언트 및 모질라 선더버드

따라서, 보다 안전한 Sign-In&lt /b&gt &lt 활성화하십시오 b&gt 합니다;;; 내 구글 계정.

이후 구글 계정 로그인하십시오 http://www. gnu. orghttp://www.:

https://myaccount.google.com/lesssecureapps &lt br />; br /&gt 또는 <; https://www.google.com/settings/security/lesssecureapps &lt br />;

C #, 다음 코드를 사용할 수 있습니다.

using (MailMessage mail = new MailMessage())
{
    mail.From = new MailAddress("email@gmail.com");
    mail.To.Add("somebody@domain.com");
    mail.Subject = "Hello World";
    mail.Body = "<h1>Hello</h1>";
    mail.IsBodyHtml = true;
    mail.Attachments.Add(new Attachment("C:\\file.zip"));

    using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))
    {
        smtp.Credentials = new NetworkCredential("email@gmail.com", "password");
        smtp.EnableSsl = true;
        smtp.Send(mail);
    }
}
해설 (0)

제 버전은 다음과 같습니다: Gmail을 사용하여 C #으로 이메일 보내기입니다.

using System;
using System.Net;
using System.Net.Mail;

namespace SendMailViaGmail
{
   class Program
   {
   static void Main(string[] args)
   {

      //Specify senders gmail address
      string SendersAddress = "Sendersaddress@gmail.com";
      //Specify The Address You want to sent Email To(can be any valid email address)
      string ReceiversAddress = "ReceiversAddress@yahoo.com";
      //Specify The password of gmial account u are using to sent mail(pw of sender@gmail.com)
      const string SendersPassword = "Password";
      //Write the subject of ur mail
      const string subject = "Testing";
      //Write the contents of your mail
      const string body = "Hi This Is my Mail From Gmail";

      try
      {
        //we will use Smtp client which allows us to send email using SMTP Protocol
        //i have specified the properties of SmtpClient smtp within{}
        //gmails smtp server name is smtp.gmail.com and port number is 587
        SmtpClient smtp = new SmtpClient
        {
           Host = "smtp.gmail.com",
           Port = 587,
           EnableSsl = true,
           DeliveryMethod = SmtpDeliveryMethod.Network,
           Credentials    = new NetworkCredential(SendersAddress, SendersPassword),
           Timeout = 3000
        };

        //MailMessage represents a mail message
        //it is 4 parameters(From,TO,subject,body)

        MailMessage message = new MailMessage(SendersAddress, ReceiversAddress, subject, body);
        /*WE use smtp sever we specified above to send the message(MailMessage message)*/

        smtp.Send(message);
        Console.WriteLine("Message Sent Successfully");
        Console.ReadKey();
     }

     catch (Exception ex)
     {
        Console.WriteLine(ex.Message);
        Console.ReadKey();
     }
    }
   }
 }
해설 (1)

난 이미 내 gmail 계정을 나에게 이해했소 작동할 수 있도록 다른 어플리케이션 액세스하려면 들어올 수 있게 된 것입니다. 이 작업은 보다 안전한 apps&quot 활성화하십시오 함께 "; 또한 이를 통해 및 링크: https://accounts.google.com/b/0/DisplayUnlockCaptcha

해설 (0)

이 코드는 좋겠다 작동합니다. 노력하잖니 있을 수 있습니다

// Include this.                
using System.Net.Mail;

string fromAddress = "xyz@gmail.com";
string mailPassword = "*****";       // Mail id password from where mail will be sent.
string messageBody = "Write the body of the message here.";

// Create smtp connection.
SmtpClient client = new SmtpClient();
client.Port = 587;//outgoing port for the mail.
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(fromAddress, mailPassword);

// Fill the mail form.
var send_mail = new MailMessage();

send_mail.IsBodyHtml = true;
//address from where mail will be sent.
send_mail.From = new MailAddress("from@gmail.com");
//address to which mail will be sent.           
send_mail.To.Add(new MailAddress("to@example.com");
//subject of the mail.
send_mail.Subject = "put any subject here";

send_mail.Body = messageBody;
client.Send(send_mail);
해설 (1)

이 포함시키십시오

using System.Net.Mail;

그리고,

MailMessage sendmsg = new MailMessage(SendersAddress, ReceiversAddress, subject, body); 
SmtpClient client = new SmtpClient("smtp.gmail.com");

client.Port = Convert.ToInt16("587");
client.Credentials = new System.Net.NetworkCredential("mail-id@gmail.com","password");
client.EnableSsl = true;

client.Send(sendmsg);
해설 (0)

아래는 코드 예제를 사용하여 apc® 송신용입니다 인할지 C #, smtp 서버를 사용하고 있는 구글의 메일 아래 예.

이 코드는 사용자의 이메일 및 비밀번호, 이메일 및 비밀번호 교체 자체 설명 할 수 있는 값을.

public void SendEmail(string address, string subject, string message)
{
    string email = "yrshaikh.mail@gmail.com";
    string password = "put-your-GMAIL-password-here";

    var loginInfo = new NetworkCredential(email, password);
    var msg = new MailMessage();
    var smtpClient = new SmtpClient("smtp.gmail.com", 587);

    msg.From = new MailAddress(email);
    msg.To.Add(new MailAddress(address));
    msg.Subject = subject;
    msg.Body = message;
    msg.IsBodyHtml = true;

    smtpClient.EnableSsl = true;
    smtpClient.UseDefaultCredentials = false;
    smtpClient.Credentials = loginInfo;
    smtpClient.Send(msg);
}
해설 (1)

이메일, 그리고 배경 아래 전송할지 스케쳐내 마십시오.

 public void SendEmail(string address, string subject, string message)
 {
 Thread threadSendMails;
 threadSendMails = new Thread(delegate()
    {

      //Place your Code here 

     });
  threadSendMails.IsBackground = true;
  threadSendMails.Start();
}

및 추가 이름공간이

using System.Threading;
해설 (0)

이 시도하시겠습니까

    private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

            mail.From = new MailAddress("your_email_address@gmail.com");
            mail.To.Add("to_address");
            mail.Subject = "Test Mail";
            mail.Body = "This is for testing SMTP mail from GMAIL";

            SmtpServer.Port = 587;
            SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
            SmtpServer.EnableSsl = true;

            SmtpServer.Send(mail);
            MessageBox.Show("mail Send");
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }
해설 (0)

한 가지 팁! 보낸 사람, 어쩌면 더 안전한 앱을 통해 확인란 메일박스와 합니다. 참조: https://www.google.com/settings/security/lesssecureapps

해설 (0)

이 방법을 사용하여

MailMessage sendmsg = new MailMessage(SendersAddress, ReceiversAddress, subject, body); 
SmtpClient client = new SmtpClient("smtp.gmail.com");

client.Port = Convert.ToInt32("587");
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("mail-id@gmail.com","MyPassWord");
client.Send(sendmsg);

39, t forget don& 이:

using System.Net;
using System.Net.Mail;
해설 (0)

Gmail 에서 변경됩니까 보낸 사람 / Outlook.com 이메일:

39 에서, 임의의 보낼 것을 막기 위해 위장 - t let Gmail/Outlook.com won& 사용자 계정 이름을.

제한된 수의 경우 보낸 사람은 이 지침에 따라 설정할 수 있습니다 다음 현장 '에서 이 주소: [메일을 보내는 내의 다른 주소] [1]

왠지 경우 전송하십시오 자의적 에서 이메일 주소 (예 피드백 양식 웹 사이트에서 여기서 사용자는 이메일 사용자가 직접 그들을 검토자의 전자 메일 진실이며당신이 don& # 39, t want) 에 최선인가 로만스였나:

        msg.ReplyToList.Add(new System.Net.Mail.MailAddress(email, friendlyName));

39, & # 39 이 방법을 사용하면 그냥 reply& 기록했다. 고객의 피드백을 할 수 있는 팬 페이지, 전자 메일 계정 질문하시리니 밴드에서만 있지만, 실제 wouldn& # 39 의 t 전달하십시오 세제곱밀리미터 스팸 메일 되는 이어질 것으로 보인다.

이 경우, re in a # 39 는 환경 you& 제어됩니다 유념하십시오 I& 잘하는 것은 아니지만, 일부 전자 메일 주소를 보냅니다 클라이언트입니다 ve seen # 39 의 경우에도 회신-수신 지정되어 (I don& # 39, 알 수 없다).

[1]: http://support.google.com/a/bin/answer.py =, = 22370 오토메이티드 en&amp hl?

해설 (0)

난 이미 했지만 같은 문제를 해결할 수 있는 앱을 덜 안전하게 이동하여 gmail& # 39 의 보안 설정 및 . 이 코드에서 도미니크 &amp. 단, 도니 작동됨 설정값입니다 사용하는 경우

로그인되었습니다 경우 따를 수 있습니다 (서비스를) 링크 및 전환하십시오 선반가공 on&quot, , , 액세스 보다 안전한 apps&quot &quot 대한 &quot.

해설 (0)
using System;
using System.Net;
using System.Net.Mail;

namespace SendMailViaGmail
{
   class Program
   {
   static void Main(string[] args)
   {

      //Specify senders gmail address
      string SendersAddress = "Sendersaddress@gmail.com";
      //Specify The Address You want to sent Email To(can be any valid email address)
      string ReceiversAddress = "ReceiversAddress@yahoo.com";
      //Specify The password of gmial account u are using to sent mail(pw of sender@gmail.com)
      const string SendersPassword = "Password";
      //Write the subject of ur mail
      const string subject = "Testing";
      //Write the contents of your mail
      const string body = "Hi This Is my Mail From Gmail";

      try
      {
        //we will use Smtp client which allows us to send email using SMTP Protocol
        //i have specified the properties of SmtpClient smtp within{}
        //gmails smtp server name is smtp.gmail.com and port number is 587
        SmtpClient smtp = new SmtpClient
        {
           Host = "smtp.gmail.com",
           Port = 587,
           EnableSsl = true,
           DeliveryMethod = SmtpDeliveryMethod.Network,
           Credentials = new NetworkCredential(SendersAddress, SendersPassword),
           Timeout = 3000
        };

        //MailMessage represents a mail message
        //it is 4 parameters(From,TO,subject,body)

        MailMessage message = new MailMessage(SendersAddress, ReceiversAddress, subject, body);
        /*WE use smtp sever we specified above to send the message(MailMessage message)*/

        smtp.Send(message);
        Console.WriteLine("Message Sent Successfully");
        Console.ReadKey();
     }
     catch (Exception ex)
     {
        Console.WriteLine(ex.Message);
        Console.ReadKey();
     }
}
}
}
해설 (0)

다음은 메일을 보내기 위한 방법 중 하나는 점점 크레덴셜이 충스러웠으니 웹스콘피그:

public static string SendEmail(string To, string Subject, string Msg, bool bodyHtml = false, bool test = false, Stream AttachmentStream = null, string AttachmentType = null, string AttachmentFileName = null)
{
    try
    {
        System.Net.Mail.MailMessage newMsg = new System.Net.Mail.MailMessage(System.Configuration.ConfigurationManager.AppSettings["mailCfg"], To, Subject, Msg);
        newMsg.BodyEncoding = System.Text.Encoding.UTF8;
        newMsg.HeadersEncoding = System.Text.Encoding.UTF8;
        newMsg.SubjectEncoding = System.Text.Encoding.UTF8;

        System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient();
        if (AttachmentStream != null && AttachmentType != null && AttachmentFileName != null)
        {
            System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(AttachmentStream, AttachmentFileName);
            System.Net.Mime.ContentDisposition disposition = attachment.ContentDisposition;
            disposition.FileName = AttachmentFileName;
            disposition.DispositionType = System.Net.Mime.DispositionTypeNames.Attachment;

            newMsg.Attachments.Add(attachment);
        }
        if (test)
        {
            smtpClient.PickupDirectoryLocation = "C:\\TestEmail";
            smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory;
        }
        else
        {
            //smtpClient.EnableSsl = true;
        }

        newMsg.IsBodyHtml = bodyHtml;
        smtpClient.Send(newMsg);
        return SENT_OK;
    }
    catch (Exception ex)
    {

        return "Error: " + ex.Message
             + "<br/><br/>Inner Exception: "
             + ex.InnerException;
    }

}

및 해당 부분을 웹스콘피그:










해설 (0)

이 번호요 시도하시겠습니까

public static bool Send(string receiverEmail, string ReceiverName, string subject, string body)
{
        MailMessage mailMessage = new MailMessage();
        MailAddress mailAddress = new MailAddress("abc@gmail.com", "Sender Name"); // abc@gmail.com = input Sender Email Address 
        mailMessage.From = mailAddress;
        mailAddress = new MailAddress(receiverEmail, ReceiverName);
        mailMessage.To.Add(mailAddress);
        mailMessage.Subject = subject;
        mailMessage.Body = body;
        mailMessage.IsBodyHtml = true;

        SmtpClient mailSender = new SmtpClient("smtp.gmail.com", 587)
        {
            EnableSsl = true,
            UseDefaultCredentials = false,
            DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network,
            Credentials = new NetworkCredential("abc@gmail.com", "pass")   // abc@gmail.com = input sender email address  
                                                                           //pass = sender email password
        };

        try
        {
            mailSender.Send(mailMessage);
            return true;
        }
        catch (SmtpFailedRecipientException ex)
        { 
          // Write the exception to a Log file.
        }
        catch (SmtpException ex)
        { 
           // Write the exception to a Log file.
        }
        finally
        {
            mailSender = null;
            mailMessage.Dispose();
        }
        return false;
}
해설 (0)

다른 답을 에서 복사, 위 방법을 작동합니까 하지만 항상 &quot 덮어씁니다 gmail from"; 및 &quot 질문하시리니 to"; 실제 gmail 계정을 통해 메일을 보내는. 그러나 근본적으로 해결할 수 없는 것은 아니다.

http://karmic-development.blogspot.in/2013/10/send-email-from-aspnet-using-gmail-as.html

&quot, 3. 계정 탭에 있는 링크를 클릭하여 다른 이메일 주소는 own&quot 추가 "; 확인 후 it&quot.

또는 기타

업데이트 3: 이 솔루션은 갈 것이라고 &quot 데릭한테 판독기에서 베넷, 당신의 gmail 계정 및 &quot default&quot, 만들기, 설정: g 메일 계정이 아닌 사용자 계정. 이로 인해 gmail # 39 를 다시 쓰기 시작, 전자 메일 주소로 함께 필드 있는모든 기본값입니다 account& is.&quot.

해설 (0)