NEW YORK (CNNMoney.com) -- There's rarely been a better time to be a refiner.

In the second quarter, refiners bought crude oil at lower prices and sold gasoline at record high prices. As a result, companies like Exxon Mobil, Chevron, and Valero could see record profits when the industry reports earnings this week.

Exxon (Charts, Fortune 500), which actually refines more barrels of oil than it pumps, could see over $11 billion in earnings, which would be the biggest quarterly profit in corporate history.

"I think you're looking at some pretty strong numbers," said Ken Carol, an oil analyst at Johnson Rice & Co. "I wouldn't be surprised to see them have record earnings."

Exxon is expected to earn $1.95 per share in the second quarter, a 14 percent increase year over year, according to Thomson Financial. Some of that boost in earnings per share is due to an aggressive share buyback program, although exactly how many shares Exxon has bought back this quarter won't be known until the company reports earnings on Thursday.

But with 5.63 billion shares outstanding as of the first quarter, that's a profit of $10.97 billion. That tops Exxon's previous record of $10.7 billion set in the fourth quarter of 2005, when hurricanes Katrina and Rita caused a surge in natural gas prices.

This quarter, it's all about the refining.

"All these refiners will have record second quarter earnings," said Fadel Gheit, a senior energy analyst at Oppenheimer. "Margins will really be very pronounced."

For instance, Carol said BP's profit on refining a barrel of oil went from $9.50 in the first quarter 2007 to $16.60 in the second quarter.

Refiners are in the money because oil prices in the second quarter hovered in the mid $60s, about $5 less than at this time last year. Oil prices dipped as production problems due to heavy maintenance and a series of accidents curbed refinery demand. Also, geopolitical tensions eased, as a peace deal was struck with Nigerian rebels and rhetoric cooled over Iran's nuclear program.

But the drop off in refining, resulted in low gasoline supplies. Combined with unabated demand from American motorists, the price of gasoline surged. The average price nationwide for a gallon of regular hit $3.227 in May, its highest ever, according to the motorists organization AAA.

F

Sunoco is expected to see earnings per share jump 19 percent, according to Thomson Financial. At Valero (Charts, Fortune 500), the nation's largest independent refiner, profits are expected to swell 26 percent. Tesoro is expected to see a 35 percent jump, and Frontier is looking at a whopping 55 percent surge.

Some of the big integrated oil companies should also do well, especially those more heavily invested in refining and ones that had the cash to buy back shares.

RoyalDutchShell, the world's second largest publicly traded oil firm behind Exxon, is expected to see earnings per share rise 11 percent when the company reports Thursday. Analysts are looking for a 9 percent increase at Chevron (Charts, Fortune 500), which reports Friday.

But others who rely less on refining, or who have had problems keeping their refineries running, are expected to slip.

ConocoPhillips (Charts, Fortune 500) is expected to see a 7 percent decline in earnings when it reports Wednesday. And BP (Charts) blamed refinery outages for a 1 percent fall in profits when it reported early Tuesday.

Looking forward, the second quarter could be as good as it gets.

Crude prices have rebounded, gaining about 7 percent in the last month as refinery production slowly ramped up. Meanwhile, the peace deal in Nigeria fell apart, and the International Energy Agency recently said it expects to see crude supplies slip and demand increase in the years ahead.

Meanwhile, gasoline futures have fallen roughly 12 percent as stockpiles increase and it appears increasing likely the nation will get through the summer driving season without any shortage.