Guest User

Untitled

a guest
Dec 11th, 2017
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. package main
  2.  
  3. import("fmt"
  4. "strings"
  5. "net"
  6. "net/smtp"
  7. "log"
  8. )
  9.  
  10. var(
  11. hostlist = make([]string,0)
  12. result = ""
  13. err error
  14. )
  15.  
  16. func main(){
  17. var toemail,fromemail string = "bharatsewani1993@gmail.com","bharatsewani@gmail.com"
  18. //var toemail string = "bharatsewani1993@gmail.com"
  19. // var getdetails bool
  20.  
  21. //get the domain name from email recipient
  22. email_arr := strings.Split(toemail,"@")
  23. domain := email_arr[1]
  24.  
  25. //get mx record of domain
  26. mxhosts,err := net.LookupMX(domain)
  27. if err != nil{
  28. panic(err)
  29. }
  30.  
  31. //if mx record not found get dns record of domain
  32. if len(mxhosts) < 1 {
  33. dnshosts,err := net.LookupNS(domain)
  34. if err != nil{
  35. panic(err)
  36. }
  37. if len(dnshosts) > 0{
  38. for i := 0; i < len(dnshosts); i++ {
  39. hostlist = append(hostlist,dnshosts[i].Host)
  40. }
  41. }
  42. } else {
  43. //found mxhosts
  44. for i := 0; i < len(mxhosts); i++ {
  45. hostlist = append(hostlist,mxhosts[i].Host)
  46. }
  47. }
  48.  
  49. //check if host list is not empty
  50. if len(hostlist) > 0{
  51. ip := hostlist[0]
  52. //connect to smtp server
  53. c, err := smtp.Dial(ip+":25")
  54. if err != nil {
  55. log.Fatal(err)
  56. }
  57.  
  58. hello := c.Hello(ip)
  59. from := c.Mail(fromemail)
  60. to := c.Rcpt(toemail)
  61. quit := c.Quit()
  62.  
  63. fmt.Println("Hello ==> ",hello)
  64. fmt.Println("From ==> ",from)
  65. fmt.Println("to ==> ",to)
  66. fmt.Println("Quit ==>", quit)
  67. // Send the email body.
  68.  
  69. } else {
  70. fmt.Println("invalid")
  71. fmt.Println("No suitable mx record found!")
  72. }
  73.  
  74. }
Add Comment
Please, Sign In to add comment