winforms - Email id address issue in c# code -
i wrote simple program in c# winforms sending email , code mentioned below:-
public partial class form1 : form { public form1() { initializecomponent(); } public mailmessage rtnmail() { string = txt_to.text; string = txt_from.text; string subject = txt_subject.text; string body = txt_body.text; mailmessage message = new mailmessage(from, to, subject, body); return message; } //button click event private void btn_send_click(object sender, eventargs e) { smtpclient smtp = new smtpclient("smtp.gmail.com"); smtp.port = 587; smtp.credentials = new system.net.networkcredential("myanotherid@gmail.com", "password"); smtp.enablessl = true; smtp.timeout = 500000; smtp.send(this.rtnmail()); } }
when run code , put values in textboxes (to, from, body, subject) , click "send" button end getting email @ address
mentioned in textbox named txt_to ( recipient gmail account id).but whenever @ address(email id) got email in microsoft
outlook (which have configued gmail recipeint account), says got email email address mentioned first argument in line of
code below,
smtp.credentials = new system.net.networkcredential("myanotherid@gmail.com", "password");
my question is, doing wrong because expect email address im receiving email( in outlook gmail) should 1 put in
textbox named txt_from rather "myanotherid@gmail.com" address.
is there work around or there exist alternate it.
i guess it's gmail's protection prevent sender spoofing.
you can't login gmail yogibear@gmail.com , send e-mail barack.obama@whitehouse.gov. gmail's smtp rewrite message's header indicate has sent e-mail.
Comments
Post a Comment